Req #70508 [Com]: Support ::function similar to ::class

[email protected] ("andreas at dqxtech dot net")
Newsgroups php.standards
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=70508&edit=1

 ID:                 70508
 Comment by:         andreas at dqxtech dot net
 Reported by:        andreas at dqxtech dot net
 Summary:            Support ::function similar to ::class
 Status:             Open
 Type:               Feature/Change Request
 Package:            PHP Language Specification
 Operating System:   Linux
 PHP Version:        7.0.0RC2
 Block user comment: N
 Private report:     N

 New Comment:

So far my workaround is:

/* @see C::foo() */
$callback = 'C::foo';

This allows the IDE to "Find usages". But I need to manually check that the @see and the string are identical.


Previous Comments:
------------------------------------------------------------------------
[2015-09-15 21:31:33] andreas at dqxtech dot net

Description:
------------
Classes like ReflectionFunction, ReflectionMethod, or built-in functions like array_filter() accept functions identified as strings.

This often leads to code like this, which is hard to analyse by the IDE:

$callback = '\MyVendor\MyLibraray\MyClass::foo';

For classes, I already use the ::class language construct to make this understandable to the IDE, and allow things like "Find usages", or to let the IDE tell me that the class does not exist.

I suggest to introduce a similar construct for functions and methods, ::function.

Test script:
---------------
class C {
  function fooMethod() {}
}

function fooFunction() {}

print C::fooMethod::function . "\n";
print fooFunction::function . "\n";

Expected result:
----------------
C::fooMethod
fooFunction


Actual result:
--------------
Fatal error: syntax error, unexpected T_DOUBLE_COLON


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



--
Edit this bug report at https://bugs.php.net/bug.php?id=70508&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.