# Changed Semantics

> Section in “Backward Incompatible Changes” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/backward-incompatible-changes/changed-semantics/>

When it comes to migrating existing code to PHP 7, backward incompatible changes to the language present the biggest challenge to application developers. It goes without saying that the PHP core developers try to avoid these types of changes at all costs. Sometimes, however, changes to PHP’s behaviour will be necessary. Luckily, in most cases, only more or less obscure edge cases will be affected. Nevertheless, you should take the time and work through your codebase, making adjustments where necessary. Determining whether a certain piece of code will be affected can be tricky, however, especially if you do not have enough test automation.

## In this section

- [Strings](https://php7explained.com/backward-incompatible-changes/changed-semantics/strings/index.html.md): Changed string semantics: hexadecimal strings are no longer numeric, a substr() edge case, non-numeric operands in PHP 7.1, mbstring case mapping in 7.3.
- [XML](https://php7explained.com/backward-incompatible-changes/changed-semantics/xml/index.html.md): DOM childNodes is an empty DOMNodeList instead of null since PHP 7.3.16 and 7.4.4, and math on SimpleXMLElement objects handles floats since PHP 7.3.
- [Arrays](https://php7explained.com/backward-incompatible-changes/changed-semantics/arrays/index.html.md): Changed array handling in PHP 7: foreach and the internal pointer, invalid list() usage and assignment order, the [] operator on empty strings, compact().
- [Mathematics](https://php7explained.com/backward-incompatible-changes/changed-semantics/mathematics/index.html.md): Changed math behavior: casting INF and NAN to integer, division and modulo by zero, bit shifts, float precision, bcmod() in PHP 7.2, rand() in PHP 7.1.
- [Session](https://php7explained.com/backward-incompatible-changes/changed-semantics/session/index.html.md): PHP 7.2 cleaned up the session extension: session functions return false on errors or in an unsupported session state, and invalid ini_set() changes fail.
- [I/O and Filesystem](https://php7explained.com/backward-incompatible-changes/changed-semantics/io-and-filesystem/index.html.md): Changed I/O semantics in PHP 7: ob_start() inside an output buffer handler raises a recoverable error, and the new jsond-based JSON parser is stricter.
- [Graphics](https://php7explained.com/backward-incompatible-changes/changed-semantics/graphics/index.html.md): Changed semantics in graphics: as of PHP 7.3, getimagesize() reports the MIME type of bitmaps as image/bmp instead of image/x-ms-bmp.
- [Operating System](https://php7explained.com/backward-incompatible-changes/changed-semantics/operating-system/index.html.md): stream_socket_get_name() wraps IPv6 addresses in brackets as of PHP 7.3, and PHP 7.4 changes stream_read() and stream_write() in stream wrappers.
- [Security](https://php7explained.com/backward-incompatible-changes/changed-semantics/security/index.html.md): Changed security behavior: imap_open() disables RSH/SSH logins by default as of PHP 7.3, and openssl_random_pseudo_bytes() throws errors as of PHP 7.4.
- [Language Features](https://php7explained.com/backward-incompatible-changes/changed-semantics/language-features/index.html.md): Changed language semantics in PHP 7: new reserved words, uniform variable syntax, errors for too few arguments in 7.1, removed extensions, heredoc in 7.3.
- [Facepalms and WTF Moments](https://php7explained.com/backward-incompatible-changes/changed-semantics/facepalms-and-wtf-moments/index.html.md): Odd constructs PHP 7 no longer tolerates: duplicate parameter names, multiple default blocks in switch, reassigning $this, count() on non-countable values.

---

Previous: [Graphics](https://php7explained.com/backward-incompatible-changes/removed-features/graphics/index.html.md) | Next: [Strings](https://php7explained.com/backward-incompatible-changes/changed-semantics/strings/index.html.md)
