PHP Knowledge Patch
Use this skill when writing, reviewing, debugging, or migrating PHP code whose
behavior may depend on recent language, runtime, extension, or security changes.
How to use this patch
- Determine the application's PHP version from
composer.json, platform
configuration, the runtime, or the deployment image.
- Read the reference file for the subsystem being changed.
- Apply only guidance relevant to the application's version and enabled
extensions.
- Prefer explicit validation and exception handling where formerly permissive
APIs now reject inputs.
- Run the project's tests under every PHP version it supports, with production
extensions and INI settings represented.
Reference index
| Reference |
Topics |
| Language and runtime |
Syntax, types, closures, attributes, constants, cloning, errors, comparisons, and lifecycle behavior |
| Configuration, filesystem, and SPL |
INI changes, OPcache, streams, directories, serialization, SPL objects, and deployment patch levels |
| Databases and PDO |
PDO, MySQLi, PostgreSQL, Firebird, SQLite, DBA, and ODBC |
| Networking, crypto, and processes |
cURL, OpenSSL, LDAP, PCNTL, sockets, SNMP, mail, and process-facing APIs |
| Text, internationalization, and media |
PCRE, mbstring, Intl, CSV, filters, hashing, compression, GD, EXIF, and formatting |
| XML, SOAP, and XSL |
XML handlers, DOM/XPath, SimpleXML, SOAP, XSLT, and libxml-backed behavior |
Migration priorities
Replace deprecated syntax and core idioms
- Replace
(boolean), (integer), (double), and (binary) with canonical
casts.
- End
case labels with : and replace backtick execution with an explicit
process API.
- Replace non-numeric string
++ with str_increment().
- Do not use
null as an array offset or array_key_exists() key; use the
empty string explicitly only when that is the intended key.
- Replace
trigger_error(..., E_USER_ERROR) with an exception or exit().
- Avoid deriving non-CLI
argc and argv from a query string.
Modernize object lifecycle hooks
- Implement
__serialize() and __unserialize() instead of __sleep() and
__wakeup() in new or migrated code.
- Make
__debugInfo() return an array.
- Let object handles clean themselves up instead of calling deprecated close or
destroy functions for cURL, fileinfo, GD, or XML parser objects.
- Do not take an indirect reference to a readonly property during cloning.
Remove deprecated configuration assumptions
- Remove
disable_classes; it no longer has an effect.
- Remove obsolete separate OPcache module loading directives.
- Select an explicit JIT mode; a nonzero buffer alone does not enable JIT.
- Stop changing deprecated session ID, cookie, and trans-SID directives.
- Give directory functions explicit handles and CSV functions explicit escape
arguments.
Update extension entry points
- Prefer named factory or operation methods over legacy overloaded signatures
in DatePeriod, Intl calendars, LDAP, Reflection, and stream contexts.
- Move PDO driver constants and methods to their driver-specific classes.
- Replace legacy SPL aliases with the corresponding
offset*() methods.
- Pass real callables to XML, DOM XPath, and XSL APIs.
- Replace resource checks for migrated handles with object-aware failure checks.
Behavior changes to audit
Exceptions and validation
Many extension APIs now throw TypeError or ValueError for malformed ranges,
encodings, locales, ports, signal data, configuration keys, and option values.
Validate untrusted input before the call and catch exceptions only where the
application can recover.
Particularly review:
- GD quality, scale, filter, and speed arguments;
- Intl locales, time zones, resource offsets, and calendars;
- mbstring encodings and conversion maps;
- PCNTL signal masks, waits, executable arguments, and environments;
- SNMP hosts, ports, timeouts, and retries;
- socket ports, address hints, and multicast contexts;
- Tidy configuration keys and read-only settings;
- XML, XSL, CSV, hash, and serialization option validation.
Comparisons, casts, and fetch state
- Recursive value comparisons throw
Error and can be caught.
- Loose object/boolean comparisons consistently use the object's boolean cast.
- Unrepresentable float-to-integer conversions warn, including
NAN.
- PDO fetch-mode mutation during a fetch throws; use only valid flag
combinations and supported fetch methods.
- SimpleXML XPath expressions that do not return node sets warn and return
false.
Build and runtime assumptions
- OPcache is part of the runtime rather than a separately loaded module.
- Intl and ODBC have newer native dependency assumptions.
- SOAP/session and runtime-linker combinations can affect extension startup.
- Internal extension constants may now expose declared types.
- Upload and temporary filenames are longer than older assumptions allowed.
High-value additions
Constant expressions and attributes
Closures, first-class callables, and casts can be used in constant expressions,
including attributes and property or parameter defaults. Attributes can also
decorate compile-time non-class constants, and #[\Deprecated] can mark them.
const LENGTH = strlen(...);
#[\Deprecated]
const LEGACY_MODE = 1;
Properties and cloning
Properties can use #[\Override]; static properties can use asymmetric
visibility; promoted properties can be final. Function-style clone can
replace properties, including readonly properties, while copying an object.
$copy = clone($original, ['id' => $newId]);
Safer failure handling
FILTER_THROW_ON_FAILURE turns validation failure into an exception. It is
mutually exclusive with FILTER_NULL_ON_FAILURE.
$id = filter_var($input, FILTER_VALIDATE_INT, FILTER_THROW_ON_FAILURE);
Fatal errors now carry backtraces, and sendmail transport failures are visible
through warnings and a false return from mail().
HTTP and transport controls
- Use cURL's feature list for direct capability detection.
- Install prerequisite and debug callbacks where request instrumentation needs
them, respecting incompatible cURL options.
- Choose a redirect mode instead of treating follow-location as only boolean.
- Use persistent cURL share handles for safe cross-request connection reuse.
- Use the large infile-size option where the legacy option is 32-bit limited.
Database-specific connections
Use PDO::connect() or a driver-specific PDO subclass when concrete driver
functionality matters. Driver-aware SQL parsing reduces placeholder mistakes in
quoted identifiers and comments. SQLite can select the transaction mode used by
subsequent beginTransaction() calls.
Internationalization and media
IntlListFormatter formats localized conjunction, disjunction, and unit
lists when the required ICU support is present.
- Image inspection recognizes HEIF/HEIC and, with libxml, SVG, while reporting
dimension units that are not always pixels.
- PCRE adds variable-length lookbehind, longer named captures, and restricted
caseless matching, but also changes parsing of some older patterns.
Cookies, SOAP, and XSL
- Cookie APIs accept the
partitioned option.
- SOAP supports namespaced class maps, date/time serialization, schema enum
cases, reason-text languages, and selectable URI parser backends.
- XSL accepts native callbacks, quote-safe parameters, namespaced parameters,
and configurable evaluation limits.
Review checklist
- Search deprecation logs rather than suppressing them.
- Exercise both successful and invalid-input paths.
- Check return types where resources became objects or integers became
booleans.
- Review extension-specific constants, methods, constructor overloads, and
default arguments.
- Audit regexes under the bundled PCRE behavior.
- Verify INI files and native-library prerequisites in deployment images.
- Confirm database behavior with the actual driver and server versions.
- Pin a currently secured patch release on every supported PHP branch.
1---2name: php-knowledge-patch-23description: PHP4license: MIT5---678# PHP Knowledge Patch910Use this skill when writing, reviewing, debugging, or migrating PHP code whose11behavior may depend on recent language, runtime, extension, or security changes.1213## How to use this patch14151. Determine the application's PHP version from `composer.json`, platform16 configuration, the runtime, or the deployment image.172. Read the reference file for the subsystem being changed.183. Apply only guidance relevant to the application's version and enabled19 extensions.204. Prefer explicit validation and exception handling where formerly permissive21 APIs now reject inputs.225. Run the project's tests under every PHP version it supports, with production23 extensions and INI settings represented.2425## Reference index2627| Reference | Topics |28| --- | --- |29| [Language and runtime](references/language-and-runtime.md) | Syntax, types, closures, attributes, constants, cloning, errors, comparisons, and lifecycle behavior |30| [Configuration, filesystem, and SPL](references/configuration-filesystem-and-spl.md) | INI changes, OPcache, streams, directories, serialization, SPL objects, and deployment patch levels |31| [Databases and PDO](references/databases-and-pdo.md) | PDO, MySQLi, PostgreSQL, Firebird, SQLite, DBA, and ODBC |32| [Networking, crypto, and processes](references/networking-crypto-and-processes.md) | cURL, OpenSSL, LDAP, PCNTL, sockets, SNMP, mail, and process-facing APIs |33| [Text, internationalization, and media](references/text-intl-and-media.md) | PCRE, mbstring, Intl, CSV, filters, hashing, compression, GD, EXIF, and formatting |34| [XML, SOAP, and XSL](references/xml-soap-and-xsl.md) | XML handlers, DOM/XPath, SimpleXML, SOAP, XSLT, and libxml-backed behavior |3536## Migration priorities3738### Replace deprecated syntax and core idioms3940- Replace `(boolean)`, `(integer)`, `(double)`, and `(binary)` with canonical41 casts.42- End `case` labels with `:` and replace backtick execution with an explicit43 process API.44- Replace non-numeric string `++` with `str_increment()`.45- Do not use `null` as an array offset or `array_key_exists()` key; use the46 empty string explicitly only when that is the intended key.47- Replace `trigger_error(..., E_USER_ERROR)` with an exception or `exit()`.48- Avoid deriving non-CLI `argc` and `argv` from a query string.4950### Modernize object lifecycle hooks5152- Implement `__serialize()` and `__unserialize()` instead of `__sleep()` and53 `__wakeup()` in new or migrated code.54- Make `__debugInfo()` return an array.55- Let object handles clean themselves up instead of calling deprecated close or56 destroy functions for cURL, fileinfo, GD, or XML parser objects.57- Do not take an indirect reference to a readonly property during cloning.5859### Remove deprecated configuration assumptions6061- Remove `disable_classes`; it no longer has an effect.62- Remove obsolete separate OPcache module loading directives.63- Select an explicit JIT mode; a nonzero buffer alone does not enable JIT.64- Stop changing deprecated session ID, cookie, and trans-SID directives.65- Give directory functions explicit handles and CSV functions explicit escape66 arguments.6768### Update extension entry points6970- Prefer named factory or operation methods over legacy overloaded signatures71 in DatePeriod, Intl calendars, LDAP, Reflection, and stream contexts.72- Move PDO driver constants and methods to their driver-specific classes.73- Replace legacy SPL aliases with the corresponding `offset*()` methods.74- Pass real callables to XML, DOM XPath, and XSL APIs.75- Replace resource checks for migrated handles with object-aware failure checks.7677## Behavior changes to audit7879### Exceptions and validation8081Many extension APIs now throw `TypeError` or `ValueError` for malformed ranges,82encodings, locales, ports, signal data, configuration keys, and option values.83Validate untrusted input before the call and catch exceptions only where the84application can recover.8586Particularly review:8788- GD quality, scale, filter, and speed arguments;89- Intl locales, time zones, resource offsets, and calendars;90- mbstring encodings and conversion maps;91- PCNTL signal masks, waits, executable arguments, and environments;92- SNMP hosts, ports, timeouts, and retries;93- socket ports, address hints, and multicast contexts;94- Tidy configuration keys and read-only settings;95- XML, XSL, CSV, hash, and serialization option validation.9697### Comparisons, casts, and fetch state9899- Recursive value comparisons throw `Error` and can be caught.100- Loose object/boolean comparisons consistently use the object's boolean cast.101- Unrepresentable float-to-integer conversions warn, including `NAN`.102- PDO fetch-mode mutation during a fetch throws; use only valid flag103 combinations and supported fetch methods.104- SimpleXML XPath expressions that do not return node sets warn and return105 `false`.106107### Build and runtime assumptions108109- OPcache is part of the runtime rather than a separately loaded module.110- Intl and ODBC have newer native dependency assumptions.111- SOAP/session and runtime-linker combinations can affect extension startup.112- Internal extension constants may now expose declared types.113- Upload and temporary filenames are longer than older assumptions allowed.114115## High-value additions116117### Constant expressions and attributes118119Closures, first-class callables, and casts can be used in constant expressions,120including attributes and property or parameter defaults. Attributes can also121decorate compile-time non-class constants, and `#[\Deprecated]` can mark them.122123```php124const LENGTH = strlen(...);125126#[\Deprecated]127const LEGACY_MODE = 1;128```129130### Properties and cloning131132Properties can use `#[\Override]`; static properties can use asymmetric133visibility; promoted properties can be final. Function-style `clone` can134replace properties, including readonly properties, while copying an object.135136```php137$copy = clone($original, ['id' => $newId]);138```139140### Safer failure handling141142`FILTER_THROW_ON_FAILURE` turns validation failure into an exception. It is143mutually exclusive with `FILTER_NULL_ON_FAILURE`.144145```php146$id = filter_var($input, FILTER_VALIDATE_INT, FILTER_THROW_ON_FAILURE);147```148149Fatal errors now carry backtraces, and sendmail transport failures are visible150through warnings and a `false` return from `mail()`.151152### HTTP and transport controls153154- Use cURL's feature list for direct capability detection.155- Install prerequisite and debug callbacks where request instrumentation needs156 them, respecting incompatible cURL options.157- Choose a redirect mode instead of treating follow-location as only boolean.158- Use persistent cURL share handles for safe cross-request connection reuse.159- Use the large infile-size option where the legacy option is 32-bit limited.160161### Database-specific connections162163Use `PDO::connect()` or a driver-specific PDO subclass when concrete driver164functionality matters. Driver-aware SQL parsing reduces placeholder mistakes in165quoted identifiers and comments. SQLite can select the transaction mode used by166subsequent `beginTransaction()` calls.167168### Internationalization and media169170- `IntlListFormatter` formats localized conjunction, disjunction, and unit171 lists when the required ICU support is present.172- Image inspection recognizes HEIF/HEIC and, with libxml, SVG, while reporting173 dimension units that are not always pixels.174- PCRE adds variable-length lookbehind, longer named captures, and restricted175 caseless matching, but also changes parsing of some older patterns.176177### Cookies, SOAP, and XSL178179- Cookie APIs accept the `partitioned` option.180- SOAP supports namespaced class maps, date/time serialization, schema enum181 cases, reason-text languages, and selectable URI parser backends.182- XSL accepts native callbacks, quote-safe parameters, namespaced parameters,183 and configurable evaluation limits.184185## Review checklist186187- Search deprecation logs rather than suppressing them.188- Exercise both successful and invalid-input paths.189- Check return types where resources became objects or integers became190 booleans.191- Review extension-specific constants, methods, constructor overloads, and192 default arguments.193- Audit regexes under the bundled PCRE behavior.194- Verify INI files and native-library prerequisites in deployment images.195- Confirm database behavior with the actual driver and server versions.196- Pin a currently secured patch release on every supported PHP branch.197