@@ -35,6 +35,27 @@ Safe-PHP code is generated automatically from the PHP doc.
3535 ` generated/ ` and the files in ` lib/ ` auto-loaded; they shouldn't
3636 need to worry about any files outside those two directories.
3737
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+
3859## Minimum Supported PHP Version
3960
4061See https://www.php.net/supported-versions.php
@@ -97,7 +118,7 @@ $ php ./safe.php generate
97118
98119### Detecting new cases
99120
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
101122documentation looking for functions which return ` false ` (or ` null ` ) on error.
102123If you want to add support for more functions to Safe-PHP, the easiest way is
103124to add more regexes here.
@@ -106,6 +127,14 @@ If you detect more cases where `false` is an exception, then you should
106127probably also edit ` Method.php::stripReturnFalseText() ` to remove the
107128"returns false on error" text from the documentation.
108129
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+
109138### Special cases
110139
111140In some cases, automatic generation is too difficult to execute and the function has to be written manually.
0 commit comments