Skip to content

Deprecation errors are inconsistently triggered for underscore class aliases #18285

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

Open
lpd-au opened this issue Apr 9, 2025 · 0 comments
Open

Comments

@lpd-au
Copy link

lpd-au commented Apr 9, 2025

Description

The following code:

<?php

namespace Foo {
    class __ {}
}

namespace Bar {
    class _ {} // Deprecated
}

namespace {
    class __ {}
    
    class_alias('Foo\__', 'Foo\_'); // Is this meant to be deprecated?
    class_alias('__', '_'); // Deprecated
}

namespace Baz {
    use Foo\_;
}

namespace Qux {
    use Foo\__ as _; // Is this meant to be deprecated?
}

Resulted in this output:

Deprecated: Using "_" as a class name is deprecated since 8.4 in /in/ZZMJs on line 8

Deprecated: Using "_" as a class alias is deprecated since 8.4 in /in/ZZMJs on line 15

But I expected this output instead:

Deprecated: Using "_" as a class name is deprecated since 8.4 in /in/ZZMJs on line 8

Deprecated: Using "_" as a class alias is deprecated since 8.4 in /in/ZZMJs on line 14

Deprecated: Using "_" as a class alias is deprecated since 8.4 in /in/ZZMJs on line 15

Deprecated: Using "_" as a class alias is deprecated since 8.4 in /in/ZZMJs on line 23

I encountered this issue while trying to migrate a large closed source project to PHP 8.4. The namespaced _ class was used as a wrapper for the gettext _ function (eg new _("string")), to delay performing the translation of cached content until the http response is stringified. The class had ~35k instantiations in source control and more instances in compressed + serialized database records. This made class aliases a potentially appealing solution, but I understand from @Girgias that these not emitting deprecation errors is an oversight.

PHP Version

8.4.1 - 8.4.6 on 3v4l

Operating System

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant