On 07/04/2019 17:08, CHU Zhaowei wrote:
In addition, I'm thinking whether it's possible and necessary to add a global strict mode (like "use strict" in js) in PHP 8 to deal with this kind of unexpected surprise. I know we have declare(strict_types=1) but it only works for functions and it's limited to call from current file.
I'm not a fan of a generic "strict mode" the way JS has it, because it only works once: if you add more behaviours later, the BC break is just as bad as if the switch wasn't there. I wonder if in 10 years time, someone will propose a "use stricter" mode.
Perl's "pragma" system is more flexible, and notably works at the file or block level, like PHP's declare statements. The most common pragmas are "strict", "warnings", and "feature", each of which has a set of sub-categories which can be individually enabled and disabled. You can also opt into all features as of a particular version (and require that version), again within a single lexical scope. The downside is that this leads to a lot of different combinations, in keeping with the Perl motto of There More Than One Way To Do It.
The big downside of all this is that even if the compiler understands what all the combinations of flags will do, the human reading the code won't necessarily, so having declare(increment_warnings=1) probably doesn't add much over just documenting the change somewhere.
Regards, -- Rowan Collins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php