[Discussion] Promoting declare failure notices to exceptions?

php.internals

Mark Randall

6 years ago
Greetings, I have created a PR that will throw exceptions when using define() with invalid types or when trying to redefine. Trying to redefine a constant or define a bad constant would throw a ValueError on the name parameter, trying to pass an unsupported type would give a TypeError on the value parameter. Normal promotions are fairly run of the mill, however for some utterly bizarre reason the existing behaviour is to print a notice and not a warning as with almost all other functions that are failing. Is there a good reason not to promote these to exceptions? https://github.com/php/php-src/pull/5265
-- Mark Randall marandall@php.net

Girgias

6 years ago
On Sat, 14 Mar 2020 at 21:19, Mark Randall <markyr@gmail.com> wrote:
> Greetings, > > I have created a PR that will throw exceptions when using define() > with invalid types or when trying to redefine. > > Trying to redefine a constant or define a bad constant would throw a > ValueError on the name parameter, trying to pass an unsupported type > would give a TypeError on the value parameter. > > Normal promotions are fairly run of the mill, however for some utterly > bizarre reason the existing behaviour is to print a notice and not a > warning as with almost all other functions that are failing. > > Is there a good reason not to promote these to exceptions? > > https://github.com/php/php-src/pull/5265 > > -- > Mark Randall > marandall@php.net > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php
I'm all for it, I wouldn't a lot of code to be affected by it as that code would be truly broken. Best regards George P. Banyard

Nikita Popov

6 years ago
On Sat, Mar 14, 2020 at 9:20 PM Mark Randall <markyr@gmail.com> wrote:
> Greetings, > > I have created a PR that will throw exceptions when using define() > with invalid types or when trying to redefine. > > Trying to redefine a constant or define a bad constant would throw a > ValueError on the name parameter, trying to pass an unsupported type > would give a TypeError on the value parameter. > > Normal promotions are fairly run of the mill, however for some utterly > bizarre reason the existing behaviour is to print a notice and not a > warning as with almost all other functions that are failing. > > Is there a good reason not to promote these to exceptions? > > https://github.com/php/php-src/pull/5265 >
This was previously discussed in the context of https://wiki.php.net/rfc/constant_redefinition. Looking back at the thread, it basically went "we should not break BC in a minor version, do it in PHP 8 instead". Well, now we have PHP 8, so let's do it. This is also the first step towards improving our optimization capabilities in this area. It's not quite enough by itself (due to early binding related issues), but it's a step in the right direction. Regards, Nikita