Bug #60620 [Csd]: ReflectionFunction Internal Error provocation
| From: | cmb@php.net | Date: | Wed, 13 Sep 2017 20:44:49 +0000 |
| Subject: | Bug #60620 [Csd]: ReflectionFunction Internal Error provocation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211139@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60620&edit=1
ID: 60620
Updated by: cmb@php.net
Reported by: hanskrentel at yahoo dot de
Summary: ReflectionFunction Internal Error provocation
Status: Closed
Type: Bug
Package: Reflection related
Operating System: win
PHP Version: 5.3.8
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> you can catch fatal errors starzing with PHP 7.0
No, that is not possible. A TypeError isn't a fatal error, though.
Previous Comments:
------------------------------------------------------------------------
[2017-09-13 17:59:37] spam2 at rhsoft dot net
that below is part of my fuzzy-call-suite for string params with work with 7.0/7.1/7.2 perfectly -
you can catch fatal errors starzing with PHP 7.0
try
{
$params[] = $reflection_param->getDefaultValue();
}
catch(Throwable $exception)
{
$params[] = bin2hex(random_bytes(5));
}
------------------------------------------------------------------------
[2017-09-13 17:22:21] cmb@php.net
As of PHP 7.0.0 a TypeError is thrown, if the parameter is not a
string, see <https://3v4l.org/DuLJt>.
------------------------------------------------------------------------
[2011-12-29 01:37:38] hanskrentel at yahoo dot de
Description:
------------
Normally Instantiation fails (ReflectionException):
$test = new ReflectionFunction('');
However this can be fooled:
$obj = new stdClass();
$test = new ReflectionFunction($obj);
echo $test;
The echo line triggers a fatal error then:
Fatal error: ReflectionFunction::__toString(): Internal error: Failed to
retrieve the reflection object
Before that happens there is a slightly misworded warning ahead:
Warning: ReflectionFunction::__construct() expects parameter 1 to be string,
object given
Misworded in the sense that it's possible objects with __toString() and
closures.
Probably something in the logic inside the constructor is not right. It would be
good if in such cases an ReflectionException is thrown on instantiation.
Test script:
---------------
$obj = new stdClass();
$test = new ReflectionFunction($obj);
echo $test;
Expected result:
----------------
ReflectionException
Actual result:
--------------
Fatal Error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60620&edit=1