Good evening,
Here’s a suggestion: Why don’t we make zend_parse_parameters emit
E_RECOVERABLE_ERROR
on failure, rather than just emitting E_WARNING
and
returning FAILURE (causing the caller to typically bail out and return NULL)?
This would bring it into line with userland type hints, which also cause such
errors. It might also cause errors to be caught sooner, as just returning NULL
can cause cryptic problems down the line. It’s worth noting that
zend_parse_parameters is very tolerant in terms of what parameters you can pass
it and is unlikely to error unless you do something really weird such as
passing an array to strlen()
. I doubt this would affect backwards compatibility
much, unless your application relies on a silenced warning (which is possible,
but discouraged behaviour), and it’s the type of BC break that would be really
obvious (your application errors and stops execution).
Thoughts?
Andrea Faulds
http://ajf.me/
Good evening,
Here’s a suggestion: Why don’t we make zend_parse_parameters emit
""Why not" is usually not a very good reason for a change in the language
syntax. " -- Stas
E_RECOVERABLE_ERROR
on failure, rather than just emittingE_WARNING
and
returning FAILURE (causing the caller to typically bail out and return NULL)?
This would bring it into line with userland type hints, which also cause such
errors. It might also cause errors to be caught sooner, as just returningNULL
can cause cryptic problems down the line. It’s worth noting that
zend_parse_parameters is very tolerant in terms of what parameters you can pass
it and is unlikely to error unless you do something really weird such as
passing an array tostrlen()
.
PHP is a looser type language... such things might be happened. and
internal functions always check their arguments.
this will make the PHP app more robust.
I doubt this would affect backwards compatibility
much, unless your application relies on a silenced warning (which is possible,
but discouraged behaviour), and it’s the type of BC break that would be really
obvious (your application errors and stops execution).
that will be a nightmare to stop people upgrade their PHP.
thanks
Thoughts?
Andrea Faulds
http://ajf.me/--
--
Xinchen Hui
@Laruence
http://www.laruence.com/
Good evening,
Here’s a suggestion: Why don’t we make zend_parse_parameters emit
""Why not" is usually not a very good reason for a change in the language
syntax. " — Stas
The reason isn’t “why not”, the reason is to improve consistency and make programs safer. This makes zpp consistent with userland type hints (less user confusion), and also means programs can failsafe rather than trundle on and do something stupid.
E_RECOVERABLE_ERROR
on failure, rather than just emittingE_WARNING
and
returning FAILURE (causing the caller to typically bail out and return NULL)?
This would bring it into line with userland type hints, which also cause such
errors. It might also cause errors to be caught sooner, as just returningNULL
can cause cryptic problems down the line. It’s worth noting that
zend_parse_parameters is very tolerant in terms of what parameters you can pass
it and is unlikely to error unless you do something really weird such as
passing an array tostrlen()
.
PHP is a looser type language... such things might be happened. and
internal functions always check their arguments.
Certain types of type shift are uncommon. zpp is extremely tolerant, as it should be in a weakly-typed language, so all of these would work:
takes_int(1);
takes_int(1.0);
takes_int(“ 123abc.7”);
takes_int(new StdClass);
takes_int(true);
It’s only in quite rare cases that zpp will actually fail and emit an error, and in these cases you probably don’t want your application to keep going. In the event you did, you could always make your error handler skip these errors. If nikic’s exceptions in the engine RFC is revived, you could even do this:
try {
takes_int($something);
} catch (InvalidArgumentException $e) {
// Handle gracefully
}
Which would be more robust than checking for === NULL, as some functions return NULL
for other reasons and this won’t spit out an E_WARNING.
To help BC, we could even make it do the old thing if @ is being used to silence it.
this will make the PHP app more robust.
I think applications are more robust if they fail early rather than plodding along because the programmer forgot an error check, and hence corrupting data or worse.
I doubt this would affect backwards compatibility
much, unless your application relies on a silenced warning (which is possible,
but discouraged behaviour), and it’s the type of BC break that would be really
obvious (your application errors and stops execution).
that will be a nightmare to stop people upgrade their PHP.
I doubt it. It’s not something you’re likely to be relying on (it’s a failure case), and if it is, you can use an error handler to skip the error and get your old behaviour.
Thanks.
Andrea Faulds
http://ajf.me/
Good evening,
Here’s a suggestion: Why don’t we make zend_parse_parameters emit
""Why not" is usually not a very good reason for a change in the language
syntax. " — StasThe reason isn’t “why not”, the reason is to improve consistency and make programs safer. This makes zpp consistent with userland type hints (less user confusion), and also means programs can failsafe rather than trundle on and do something stupid.
E_RECOVERABLE_ERROR
on failure, rather than just emittingE_WARNING
and
returning FAILURE (causing the caller to typically bail out and return NULL)?
This would bring it into line with userland type hints, which also cause such
errors. It might also cause errors to be caught sooner, as just returningNULL
can cause cryptic problems down the line. It’s worth noting that
zend_parse_parameters is very tolerant in terms of what parameters you can pass
it and is unlikely to error unless you do something really weird such as
passing an array tostrlen()
.
PHP is a looser type language... such things might be happened. and
internal functions always check their arguments.Certain types of type shift are uncommon. zpp is extremely tolerant, as it should be in a weakly-typed language, so all of these would work:
takes_int(1); takes_int(1.0); takes_int(“ 123abc.7”); takes_int(new StdClass); takes_int(true);
It’s only in quite rare cases that zpp will actually fail and emit an error, and in these cases you probably don’t want your application to keep going. In the event you did, you could always make your error handler skip these errors. If nikic’s exceptions in the engine RFC is revived, you could even do this:
try { takes_int($something); } catch (InvalidArgumentException $e) { // Handle gracefully }
Which would be more robust than checking for === NULL, as some functions return
NULL
for other reasons and this won’t spit out an E_WARNING.
It's also worth noting that the "return NULL
on zpp failure"
convention is not followed to the letter, I have seen places that
RETURN_FALSE - I can't remember exactly where I have seen this but I
will dig a ref out if anyone wants it.
To help BC, we could even make it do the old thing if @ is being used to silence it.
Don't like this
this will make the PHP app more robust.
I think applications are more robust if they fail early rather than plodding along because the programmer forgot an error check, and hence corrupting data or worse.
+1
I doubt this would affect backwards compatibility
much, unless your application relies on a silenced warning (which is possible,
but discouraged behaviour), and it’s the type of BC break that would be really
obvious (your application errors and stops execution).
that will be a nightmare to stop people upgrade their PHP.I doubt it. It’s not something you’re likely to be relying on (it’s a failure case), and if it is, you can use an error handler to skip the error and get your old behaviour.
Thanks.
Andrea Faulds
http://ajf.me/
I'm roughly -0.5 on this proposal overall. I'd like this to be easily
handleable in userland, but I don't like E_RECOVERABLE_ERROR
(in
general, not just here). I'd very much support this if it used
exceptions, though.
Thanks, Chris
It's also worth noting that the "return
NULL
on zpp failure"
convention is not followed to the letter, I have seen places that
RETURN_FALSE - I can't remember exactly where I have seen this but I
will dig a ref out if anyone wants it.
Good point. This is also, it has to be said, quite rarely documented. I’m not sure we even document zip’s behaviour anywhere in the manual, which means users don’t know what to expect.
To help BC, we could even make it do the old thing if @ is being used to silence it.
Don't like this
I’m not sure I do either, it’s merely a suggestion if it would help BC, but it probably not a good idea, as @ should only suppress errors, not change behaviour.
I'm roughly -0.5 on this proposal overall. I'd like this to be easily
handleable in userland, but I don't likeE_RECOVERABLE_ERROR
(in
general, not just here). I'd very much support this if it used
exceptions, though.
Perhaps this could be postponed until Nikita Popov can revive his Exceptions in the Engine RFC. If that were to pass, I could make an RFC for this.
Andrea Faulds
http://ajf.me/
Le lun. 1 sept. 2014 à 20:13, Andrea Faulds ajf@ajf.me a écrit :
It's also worth noting that the "return
NULL
on zpp failure"
convention is not followed to the letter, I have seen places that
RETURN_FALSE - I can't remember exactly where I have seen this but I
will dig a ref out if anyone wants it.Good point. This is also, it has to be said, quite rarely documented. I’m
not sure we even document zip’s behaviour anywhere in the manual, which
means users don’t know what to expect.To help BC, we could even make it do the old thing if @ is being used
to silence it.Don't like this
I’m not sure I do either, it’s merely a suggestion if it would help BC,
but it probably not a good idea, as @ should only suppress errors, not
change behaviour.I'm roughly -0.5 on this proposal overall. I'd like this to be easily
handleable in userland, but I don't likeE_RECOVERABLE_ERROR
(in
general, not just here). I'd very much support this if it used
exceptions, though.Perhaps this could be postponed until Nikita Popov can revive his
Exceptions in the Engine RFC. If that were to pass, I could make an RFC for
this.Andrea Faulds
http://ajf.me/
I don't have an opinion yet as I have to think a bit more about it.
I have the impression that giving the user to bail out on specific error
levels would be less intrusive as he would be able to opt-in for it. See
the "Pedantic errors (Was: Re: [PHP-DEV] [RFC][VOTE] Improve array to
string conversion)" thread. I would be glad to gather some opinions to see
if it is worth investigating.
Cheers,
Patrick