|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-12-29 01:37 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 09 09:00:01 2025 UTC |
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)); }