@@ -35,6 +35,27 @@ Safe-PHP code is generated automatically from the PHP doc.
35
35
` generated/ ` and the files in ` lib/ ` auto-loaded; they shouldn't
36
36
need to worry about any files outside those two directories.
37
37
38
+ ### Compatibility with upstream PHP
39
+
40
+ Intentional changes:
41
+ * Functions which return a special value to indicate an error should now throw an ` Exception ` .
42
+ * eg ` file_get_contents() ` returns a ` string ` on success, or returns ` false ` on error.
43
+ ` \Safe\file_get_contents() ` returns a ` string ` on success and throws an ` Exception ` on error.
44
+ * If the return type included that type only for errors, that type is removed from the signature.
45
+ * eg ` file_get_contents() ` returns ` string|false ` , ` \Safe\file_get_contents() ` returns ` string `
46
+ * ` proc_close() ` returns the process exit code on success and -1 on error.
47
+ Both of these are ` int ` , so the signature remains ` int ` .
48
+ * If the function returned ` true ` on success and ` false ` on error, and we have
49
+ removed the ` false ` , then the signature gets changed from ` bool ` to ` void ` to
50
+ stop people from accidentally writing ` if(function()) {...} `
51
+
52
+ Necessary changes / side effects:
53
+ * Functions which have optional parameters without defaults (eg ` cubrid_bind() ` has
54
+ ` $bind_value_type ` ) are turned into functions with nullable parameters which
55
+ default to ` null ` .
56
+ * PHP's internal error marker (The thing retrieved by ` error_get_last() ` ) will be cleared
57
+ each time a Safe function is called.
58
+
38
59
## Minimum Supported PHP Version
39
60
40
61
See https://www.php.net/supported-versions.php
@@ -97,7 +118,7 @@ $ php ./safe.php generate
97
118
98
119
### Detecting new cases
99
120
100
- ` generator/src/XmlDocParser/DocPage .php ` uses a list of regexes to scan the
121
+ ` generator/config/detectErrorType .php ` uses a list of regexes to scan the
101
122
documentation looking for functions which return ` false ` (or ` null ` ) on error.
102
123
If you want to add support for more functions to Safe-PHP, the easiest way is
103
124
to add more regexes here.
@@ -106,6 +127,14 @@ If you detect more cases where `false` is an exception, then you should
106
127
probably also edit ` Method.php::stripReturnFalseText() ` to remove the
107
128
"returns false on error" text from the documentation.
108
129
130
+ ### Deprecating old cases
131
+
132
+ If the unsafe-function-detector has made a false-positive (ie, it has detected
133
+ a function returns ` false ` on error, when actually ` false ` is fine), then we
134
+ don't want to completely remove the function because that would break backwards
135
+ compatibility, but we can hide the function to avoid it being suggested to
136
+ new users.
137
+
109
138
### Special cases
110
139
111
140
In some cases, automatic generation is too difficult to execute and the function has to be written manually.
0 commit comments