Bug #72305 [Ana]: ReflectionParameter::isCallable is not implemented properly

From: Date: Sat, 10 Dec 2016 18:36:50 +0000
Subject: Bug #72305 [Ana]: ReflectionParameter::isCallable is not implemented properly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205895@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72305&edit=1

 ID:                 72305
 Updated by:         cmb@php.net
 Reported by:        php at abiusx dot com
 Summary:            ReflectionParameter::isCallable is not implemented
                     properly
 Status:             Analyzed
 Type:               Bug
 Package:            Reflection related
 Operating System:   OS X
 PHP Version:        7.0.7
 Block user comment: N
 Private report:     N

 New Comment:

If I'm not mistaken, the API is available as of PHP 7.0.0 by means of
ZEND_ARG_CALLABLE_INFO()[1]. So "only" the arginfo would have to be updated.

[1] <https://github.com/php/php-src/blob/PHP-7.0.0/Zend/zend_API.h#L106>


Previous Comments:
------------------------------------------------------------------------
[2016-06-08 04:00:02] pollita@php.net

Your analysis is correct.  Internal functions don't /really/ have typehints in the way that
userland functions do.  What we have instead is c-array which says "object-of-class",
"array", or "other", and whether or not the arg is taken by reference.  In other
words, just about the least possible amount of metadata that makes sense.

Types *are* verified for internal functions at runtime, but only during the call during dispatch to
a magic function which plucks args off the stack and coerces them as needed.  This is unfortunately
entirely opaque to Reflection.  There's just no means to gain visibility using the current
extension api structures.

So to the meat of the issue; Can we fix it? Yes, but not trivially, and certainly not in time for
7.1.

Sorry... :/

------------------------------------------------------------------------
[2016-05-31 17:30:25] php at abiusx dot com

Description:
------------
ReflectionParameter::isCallable always returns false.



Test script:
---------------
<?php
foreach (get_defined_functions()['internal'] as $f)
{
	$rf=new ReflectionFunction($f);
	for ($i=0;$i<$rf->getNumberOfParameters();++$i)
	{
		$rp=new ReflectionParameter($f,$i);
		if ($rp->isCallable())
			echo $f," parameter ",$i,PHP_EOL;
	}
}


Expected result:
----------------
It should return true for some parameters of some internal functions, e.g. array_map param0.

Actual result:
--------------
Always false.
As far as I checked, http://lxr.php.net/xref/PHP_7_0/ext/reflection/php_reflection.c#6413

it appears that isCallable is never set in the typehint of the function, and the issue is not with
reflection, but with the way functions are stored.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72305&edit=1


Thread (7 messages)

« previous php.bugs (#205895) next »