php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72305 ReflectionParameter::isCallable is not implemented properly
Submitted: 2016-05-31 17:30 UTC Modified: 2020-06-28 09:49 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: php at abiusx dot com Assigned: cmb (profile)
Status: Closed Package: Reflection related
PHP Version: 7.0.7 OS: OS X
Private report: No CVE-ID: None
 [2016-05-31 17:30 UTC] 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.

Patches

reflection-callable-poc (last revision 2016-12-10 18:57 UTC by cmb@php.net)

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-08 04:00 UTC] pollita@php.net
-Status: Open +Status: Analyzed
 [2016-06-08 04:00 UTC] 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-12-10 18:36 UTC] cmb@php.net
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>
 [2016-12-10 18:57 UTC] cmb@php.net
The following patch has been added/updated:

Patch Name: reflection-callable-poc
Revision:   1481396260
URL:        https://bugs.php.net/patch-display.php?bug=72305&patch=reflection-callable-poc&revision=1481396260
 [2017-01-11 09:13 UTC] krakjoe@php.net
-Assigned To: +Assigned To: cmb
 [2017-01-11 09:13 UTC] krakjoe@php.net
Christoph, assigning this to you, can you chase Anatol and find out if this is okay for 7.0.

It's fine in 7.1 and master.

Commit when confirmed, thank you.
 [2017-01-12 16:28 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 [2019-09-29 14:05 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2019-09-29 14:05 UTC] cmb@php.net
For the record, this had to be postponed to PHP 8[1], and is still
work in progress.

[1] <https://externals.io/message/105970>
 [2019-11-04 09:45 UTC] cmb@php.net
-Status: Analyzed +Status: Suspended
 [2019-11-04 09:45 UTC] cmb@php.net
Well, since we're working on this, I suspend this ticket.
 [2020-06-28 09:49 UTC] cmb@php.net
-Status: Suspended +Status: Closed
 [2020-06-28 09:49 UTC] cmb@php.net
The parameter types of internal functions are now supposed to be
available for the core and bundled extensions.

Note though, that ReflectionParameter::isCallable() has been
deprecated, and you're supposed to use
ReflectionParameter::getType() and the ReflectionType API instead.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 13:01:30 2024 UTC