Hi. I hate to ask an outright question on the list rather but I've been
searching the last 5 hours for an answer to this and haven't found anything
and it's a rather tight corner case. I'm working on a small package for PHP
5.x that uses set_error_handler()
to convert E_RECOVERABLE_ERRORs to the
appropriate PHP 7 exceptions. I know I can't emulate things exactly - my
goal is to get things so that PHPUnit tests can use the same
@expectedException annotation for these scenarios, simplifying unit test
writing.
As far as my research has found E_RECOVERABLE_ERROR
has only ever been used
for type hint failures. Are there any other errors that have this type,
and if so to what PHP 7 exception should they be converted?
Michael Morris wrote on 21/07/2015 18:11:
Hi. I hate to ask an outright question on the list rather but I've been
searching the last 5 hours for an answer to this and haven't found anything
and it's a rather tight corner case. I'm working on a small package for PHP
5.x that usesset_error_handler()
to convert E_RECOVERABLE_ERRORs to the
appropriate PHP 7 exceptions. I know I can't emulate things exactly - my
goal is to get things so that PHPUnit tests can use the same
@expectedException annotation for these scenarios, simplifying unit test
writing.As far as my research has found
E_RECOVERABLE_ERROR
has only ever been used
for type hint failures. Are there any other errors that have this type,
and if so to what PHP 7 exception should they be converted?
You should be able to figure out with a grep of the source code for use
of that constant (it has the same name in C as in PHP). A quick glance
on lxr.php.net shows a few other uses:
http://lxr.php.net/search?q=&defs=&refs=E_RECOVERABLE_ERROR&path=&hist=&project=PHP_5_6
Regards,
Rowan Collins
[IMSoP]
I was provided with such a grep of PHP 5.6 and have begun the mapping. I've
set up this composer package for it.
https://packagist.org/packages/aki-tendo/php7exception
and the git if someone has some time to chip in.
https://github.com/TendoAki/php-7-exceptions-in-php-5
Currently I have AssertionError mapped since that is dirt simple to do.
From here out it's a bit more unclear. Now, the main goal here is to make
the @expectedException annotation work the same way in PHP 5 and 7 for
these errors. That said, how many of these will actually get units aimed at
them? Probably not many.
My first thought is to strpos the message string for the word "Argument"
and if that returns 0 then I know it's a TypeError and can throw that.
Apparently eval() can raise E_RECOVERABLE, so that maps to ParseError. All
others to Error?
I would appreciate some guidance on this - smoothing the transition from 5
to 7 helps all of us.
On Tue, Jul 21, 2015 at 1:44 PM, Rowan Collins rowan.collins@gmail.com
wrote:
Michael Morris wrote on 21/07/2015 18:11:
Hi. I hate to ask an outright question on the list rather but I've been
searching the last 5 hours for an answer to this and haven't found
anything
and it's a rather tight corner case. I'm working on a small package for
PHP
5.x that usesset_error_handler()
to convert E_RECOVERABLE_ERRORs to the
appropriate PHP 7 exceptions. I know I can't emulate things exactly - my
goal is to get things so that PHPUnit tests can use the same
@expectedException annotation for these scenarios, simplifying unit test
writing.As far as my research has found
E_RECOVERABLE_ERROR
has only ever been
used
for type hint failures. Are there any other errors that have this type,
and if so to what PHP 7 exception should they be converted?You should be able to figure out with a grep of the source code for use of
that constant (it has the same name in C as in PHP). A quick glance on
lxr.php.net shows a few other uses:
http://lxr.php.net/search?q=&defs=&refs=E_RECOVERABLE_ERROR&path=&hist=&project=PHP_5_6Regards,
Rowan Collins
[IMSoP]