Skip to content

Commit 9d1e36e

Browse files
committed
Some more UPGRADING changes
1 parent 7d0e3c0 commit 9d1e36e

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

UPGRADING

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,17 @@ Changes to parameter handling
191191

192192
Relevant RFC: https://wiki.php.net/phpng
193193

194-
Changes to integer operations
195-
-----------------------------
194+
Changes to integer handling
195+
---------------------------
196+
197+
* Invalid octal literals (containing digits larger than 7) now produce compile
198+
errors. For example, the following is no longer valid:
199+
200+
$i = 0781; // 8 is not a valid octal digit!
201+
202+
Previously the invalid digits (and any following valid digits) were simply
203+
ignored. As such $i previously held the value 7, because the last two digits
204+
were silently discarded.
196205

197206
* Bitwise shifts by negative numbers will now throw a warning and return false:
198207

@@ -211,10 +220,33 @@ Changes to integer operations
211220
* Similarly right bitwise shifts by a number of bits beyond the bit width of an
212221
integer will always result in 0 or -1 (depending on sign):
213222

214-
var_dump(1 >> 64); // int(0)
215-
var_dump(-1) >> 64); // int(-1)
223+
var_dump(1 >> 64); // int(0)
224+
var_dump(-1 >> 64); // int(-1)
225+
226+
* Strings that contain hexadecimal numbers are no longer considered to be
227+
numeric and don't receive special treatment anymore. Some examples of the
228+
new behavior:
216229

217-
Relevant RFC: https://wiki.php.net/rfc/integer_semantics
230+
var_dump("0x123" == "291"); // bool(false) (previously true)
231+
var_dump(is_numeric("0x123")); // bool(false) (previously true)
232+
var_dump("0xe" + "0x1"); // int(0) (previously 16)
233+
234+
var_dump(substr("foo", "0x1")); // string(3) "foo" (previously "oo")
235+
// Notice: A non well formed numeric value encountered
236+
237+
filter_var() can be used to check if a string contains a hexadecimal number
238+
or convert such a string into an integer:
239+
240+
$str = "0xffff";
241+
$int = filter_var($str, FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX);
242+
if (false === $int) {
243+
throw new Exception("Invalid integer!");
244+
}
245+
var_dump($num); // int(65535)
246+
247+
Relevant RFCs:
248+
* https://wiki.php.net/rfc/integer_semantics
249+
* https://wiki.php.net/rfc/remove_hex_support_in_numeric_strings
218250

219251
Other core changes
220252
------------------
@@ -238,15 +270,7 @@ Other core changes
238270
. Added zend_memnrstr, zend_memnrstr_ex.
239271
. Added hybrid sorting algo zend_sort for better performance.
240272
. Added stable sorting algo zend_insert_sort.
241-
. Invalid octal literals in source code now produce compile errors, fixing
242-
PHPSadness #31. Previously, the invalid digits (and any following valid
243-
digits) were simply ignored, such that 0781 became 7.
244273
. Removed dl() function on fpm-fcgi.
245-
. Removed support for hexadecimal numeric strings. This means that some
246-
operations like == will no longer specially interpret strings containing
247-
hexadecimal numbers. Furthermore is_numeric() will not consider hexadecimal
248-
strings to be numeric (use FILTER_VALIDATE_INT instead).
249-
(RFC: https://wiki.php.net/rfc/remove_hex_support_in_numeric_strings)
250274
. $HTTP_RAW_POST_DATA is no longer available. Use the php://input stream instead.
251275

252276
Other

0 commit comments

Comments
 (0)