-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReflectionFunction::getNamespaceName() is still broken for closures in PHP 8.4 #18070
Comments
Hi @jlherren. This isn't really a bug. Namespaces in PHP are really just prefixes to class/function/constant names. Since closures are anonymous, they don't have a meaningful name, and thus don't have a prefix that is needed for context/disambiguation. Nonetheless, in what context would this be relevant to you? |
I see how it makes sense that closures don't really have a namespace. But it's relevant because it breaks code that relied on the previous behavior present all the way back to PHP 5.3. If you say that the previous behavior was unintended or unsupported, then it may not be classified as a bug, but it still represents a rather unfortunate backward compatibility break. One thing it breaks is |
Indeed. It's an unfortunate and unanticipated backwards compatibility break - exactly for the reason that closures do not have a meaningful name by definition. But I'm not sure if this is fixable now that PHP 8.4 is released and folks already adapted their code to support the closure naming format. laravel/serializable-closure already uses the tokenizer to parse the file and look up the |
To give an example: The library also fails to correctly serialize property hooks. This example: <?php
use Laravel\SerializableClosure\SerializableClosure;
require_once __DIR__ . '/vendor/autoload.php';
$closure = function () {
return new class {
public string $foo {
get {
return 'test';
}
}
};
};
$serialized = serialize(new SerializableClosure($closure));
echo "Serialized: $serialized\n";
$closure = unserialize($serialized)->getClosure();
echo 'Received: ', $closure(), "\n"; results in:
… adding an extra The fact that we are already at PHP 8.4.5 and other libraries already adapted their code to the new closure naming format of PHP 8.4, changing this in the PHP 8.4.x cycle would result in a(nother) breaking change. Combined with the fact that this issue only affects libraries that try to do relative symbol lookups, which already need the tokenizer to find out about I'm therefore closing this issue as a “Won't fix”. |
Description
The following code:
Resulted in this output:
But I expected this output instead (as output by PHP 8.1, 8.2 and 8.3):
Also see possibly related #16122.
PHP Version
PHP 8.4.5
Operating System
Official docker image php:8.4-cli
The text was updated successfully, but these errors were encountered: