Deprecate passing null to non-nullable arg of internal function#6475
Deprecate passing null to non-nullable arg of internal function#6475nikic wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
Shouldn't it say "Passing null as argument" or "Passing null to parameter"?
There was a problem hiding this comment.
I've changed it to say "Passing null to parameter".
There was a problem hiding this comment.
I decided to thread through the argument number after all, and provide a more detailed error message:
Deprecated: date_interval_create_from_date_string(): Passing null to parameter #1 ($datetime) of type string is deprecated
dd4e487 to
545a30b
Compare
|
Yay, all tests passing. |
DescriptionHello internals, I'm writing to express concern about two major deprecations that exist in PHP 8.4 that fundamentally change PHP's character as a loosely-typed language: null coercion in internal functions and dynamic property creation. Both are set to become hard errors in PHP 9.0. Issue 1: Null Coercion in Internal FunctionsPHP has always been a loosely-typed language where null, empty string, and false are interchangeable in most contexts. This wasn't a bug—it was a feature that made PHP accessible and reduced boilerplate. Functions like The current trajectory forces millions of lines of existing code to add defensive Issue 2: Dynamic Property DeprecationsThe ability to create properties on the fly has been another core strength of PHP. For objects without typed properties—or properties that don't need to always be defined—dynamic property creation provided flexibility without ceremony. This is especially valuable for:
Deprecating this adds no value for untyped properties and forces developers to pre-declare every possible property or add boilerplate like The ProposalMake both strictness changes opt-in features in PHP 9.0, similar to
This respects both philosophies: teams wanting strictness can adopt it, while codebases built on PHP's traditional loose typing aren't forced into large-scale rewrites for behavior changes that don't fix actual bugs. Why This MattersDecades of PHP code were written expecting these behaviors. Breaking backward compatibility at this scale—while claiming to maintain PHP's identity as a loosely-typed language—feels contradictory. The interchangeability of null and empty values, and the flexibility of dynamic properties, are PHP's strengths, not weaknesses to be eliminated. I'd welcome discussion on whether these strict behaviors could remain optional rather than mandatory in 9.0. Thank you for considering this feedback. |
|
This is not the mailing list. Do not comment on old PRs. If you want to discuss this, do this via the proper channel as outlined in #21145 (comment). |
Implementation for https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg.
TODO: