-
Notifications
You must be signed in to change notification settings - Fork 7.8k
[PHP 8.3] constants have their namespace lowercased #11423
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
Comments
Uhh, thanks for raising this issue! I'll definitely look at it ASAP, possibly tomorrow. |
The behaviour which causes the issue was introduced in e2ad4e01780bf1e6cba162750946b9adfc40526b for fixing a bug. UPDATE: case-insensitive constants are irrelevant here, since this bug is about the namespace. |
UPDATE: I'm a bit tired I guess... Of course, this behavior is the result of my changes in PHP 8.3.. And previously, the constant names were displayed with the correct casing. So do you guys think that my changes should be reverted? Or do you see any reasonable fix for the problem? @Girgias @iluuu1994 |
This is not limited to internal constants. --TEST--
get_defined_constants() namespace casing
--FILE--
<?php
namespace Foo {
const BAR = 'BAR';
}
namespace {
foreach (get_defined_constants() as $name => $value) {
if ($value === 'BAR') {
var_dump($name);
}
}
}
?>
--EXPECT--
string(7) "foo\BAR" Tbh I don't believe shrinking the size of constants is particularly important. We're saving 8 bytes per constant. It doesn't matter too much for space or cache locality. We do try to preserve casing in most cases, including error messages. There is already an edge case where the name casing is not preserved: php/doc-en#2383. Casing consistency is not a huge deal to me, but I'm not sure if we should intentionally break unless there is a clear win. |
I didn't know we stored namespaces in lowercase form. Is this because of how we store namespaces in a similar way to class/function names which are case insensitive? |
@Girgias Yes, namespaces are case-insensitive, the constant itself is not. So the namespace is lower-cased for canonicalization. The original constant name was previously stored in |
TIL, thanks for the expllanation! |
Indeed, title updated to reflect this fact. |
Unfortunately, without storing the original names somewhere, they will be lost in time like tears in the rain. I can't see any viable solution other than retire the changes... |
With somewhat sad heart, I've just reverted my commit :( |
Hi @kocsismate, I tried a new build from |
I had to revert the revert because it caused segfaults in CI. I'll have to take a closer look why. |
Ah sorry, I guess the Maybe the issue should be reopened then? |
Description
The following code:
Resulted in this output:
But I expected this output instead:
This also affects user-defined constants, see #11423 (comment).
This behaviour was introduced in php 8.3 by the removal of the
name
field of thezend_constant
struct in f42992f (#10954).PHP Version
PHP 8.3-dev
Operating System
irrelevant
The text was updated successfully, but these errors were encountered: