Bug #60620 [Com]: ReflectionFunction Internal Error provocation
Edit report at https://bugs.php.net/bug.php?id=60620&edit=1
ID: 60620
Comment by: spam2 at rhsoft dot 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:
> No, that is not possible. A TypeError isn't a fatal error, though
no idea what you are talking about - you can catch it - PERIOD
the only crap you still can't catch is https://bugs.php.net/bug.php?id=73451
[harry@srv-rhsoft:/downloads]$ php test.php
CATCHED: TypeError: Argument 1 passed to test() must be of the type string, integer given, called in
/mnt/data/downloads/test.php on line 4 and defined in /mnt/data/downloads/test.php:11 Stack trace:
#0 /mnt/data/downloads/test.php(4): test(1) #1 {main}
[harry@srv-rhsoft:/downloads]$ cat test.php
<?php declare(strict_types=1);
try
{
test(1);
}
catch(Throwable $exception)
{
$exception = str_replace("\n", ' ', (string)$exception);
echo "CATCHED: $exception\n";
}
function test(string $x)
{
}
Previous Comments:
------------------------------------------------------------------------
[2017-09-13 20:44:49] cmb@php.net
> you can catch fatal errors starzing with PHP 7.0
No, that is not possible. A TypeError isn't a fatal error, though.
------------------------------------------------------------------------
[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
Thread (7 messages)