-
-
Save adsr/2c0b9243986418af3cecf8046657304b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Proposal: Support `::function` syntax for sake of readability, static | |
// analysis, and consistency with `::class` syntax. | |
// For example, instead of: | |
call_user_func('printf', "hello\n"); | |
// favor: | |
call_user_func(printf::function, "hello\n"); | |
// Cases which some may find helpful/explicit, others may find confusing: | |
class X { | |
const F = printf::function; | |
static function sf($x) { return printf($x); } | |
function f($x) { return printf($x); } | |
static function ff() { return self::F; } | |
}; | |
$x = new X(); | |
call_user_func('printf'::function, "A\n"); | |
call_user_func([$x, 'f']::function, "B\n"); | |
call_user_func('X::sf'::function, "C\n"); | |
call_user_func(X::F::function, "D\n"); | |
call_user_func((fn ($x) => printf($x))::function, "E\n"); | |
call_user_func((fn () => 'printf')()::function, "F\n"); | |
// Needless case: | |
var_dump(printf::function::function::function); | |
// The proof-of-concept patch breaks in the case below. I think it may require | |
// altering ZEND_FETCH_CLASS_NAME, or emitting a new opcode, or reserving | |
// the field name `function` as we do with `class`. | |
class Y { | |
const function = 'Z'; | |
} | |
var_dump(Y::function); // should be "Z", but is "Y" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment