Req #70508 [Opn->Sus]: Support ::function similar to ::class
| From: | krakjoe@php.net | Date: | Sat, 26 Mar 2016 21:46:02 +0000 |
| Subject: | Req #70508 [Opn->Sus]: Support ::function similar to ::class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200125@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70508&edit=1
ID: 70508
Updated by: krakjoe@php.net
Reported by: andreas at dqxtech dot net
Summary: Support ::function similar to ::class
-Status: Open
+Status: Suspended
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.0.0RC2
Block user comment: N
Private report: N
New Comment:
For this kind of change, an RFC is required.
Please see: https://wiki.php.net/rfc/howto
Previous Comments:
------------------------------------------------------------------------
[2015-12-19 04:23:58] ajf@php.net
Or, well, PHP does not have an autoloader for functions just now. But if it did, this would be a
problem. And either way we can't do it at compile-time.
------------------------------------------------------------------------
[2015-12-19 04:23:14] ajf@php.net
The problem with functions is that in a namespace, if you do, say,
foo(), PHP
can't know whether that's \foo() or \someNamespace\foo() without
running the autoloader.
------------------------------------------------------------------------
[2015-09-15 22:29:57] andreas at dqxtech dot net
Well..
> See also https://wiki.php.net/rfc/function_referencing
> (withdrawn) which suggests
> $callback = &\MyVendor\MyLibrary\MyClass::foo;
This is different in that it is meant to return a reference, whereas ::function would just return a
string.
I am not convinced of the reference stuff, but I strings are nice and plain and simple.
> There's the discussion for it too
> http://marc.info/?t=140710275400001&r=2&w=2
> where "::function" also makes an appearance, but both solutions have problems.
I read the issues some people raised for ::function, but I don't agree.
First, I don't know if the discussion meant ::function to return a reference or a string. I am
very much advocating it to return a string, so it is consistent with ::class, and also has a simpler
behavior.
The supposed ambiguity of AmIAFunctionOrAClass::function is not really a problem.
Right now, ::class does not trigger autoloading. Therefore, NonExistingClass::class will just return
the class name, with no complaining.
Even existingFunction::class, for an existing function, will return "existingFunction" as
if it was a class.
Likewise, ExistingClass::function should simply return "ExistingClass" as if it was a
function. It should simply not care.
Otherwise, the mechanic behavior would depend on whether a class was already autoloaded or not. This
would suck.
In fact ::class can already be abused as a funny alternative to string constants :)
------------------------------------------------------------------------
[2015-09-15 21:50:16] requinix@php.net
See also https://wiki.php.net/rfc/function_referencing
(withdrawn) which suggests
$callback = &\MyVendor\MyLibrary\MyClass::foo;
There's the discussion for it too
http://marc.info/?t=140710275400001&r=2&w=2
where "::function" also makes an appearance, but both solutions have problems.
------------------------------------------------------------------------
[2015-09-15 21:34:55] andreas at dqxtech dot net
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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=70508
--
Edit this bug report at https://bugs.php.net/bug.php?id=70508&edit=1