Skip to content

Errors about interface/trait/enum names say "class name" #15976

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

Closed
DanielEScherzer opened this issue Sep 21, 2024 · 2 comments
Closed

Errors about interface/trait/enum names say "class name" #15976

DanielEScherzer opened this issue Sep 21, 2024 · 2 comments

Comments

@DanielEScherzer
Copy link
Member

DanielEScherzer commented Sep 21, 2024

Description

The following code:

<?php
namespace enum_demo {
    enum _ {}
}
namespace interface_demo {
    interface _ {}
}
namespace trait_demo {
    trait _ {}
}
namespace class_demo {
    class _ {}
}

Resulted in this output:

Deprecated: Using "_" as a class name is deprecated since 8.4 in /in/2mWrG on line 4

Deprecated: Using "_" as a class name is deprecated since 8.4 in /in/2mWrG on line 7

Deprecated: Using "_" as a class name is deprecated since 8.4 in /in/2mWrG on line 10

Deprecated: Using "_" as a class name is deprecated since 8.4 in /in/2mWrG on line 13

But I expected this output instead:

Deprecated: Using "_" as an enum name is deprecated since 8.4 in /in/2mWrG on line 4

Deprecated: Using "_" as an interface name is deprecated since 8.4 in /in/2mWrG on line 7

Deprecated: Using "_" as a trait name is deprecated since 8.4 in /in/2mWrG on line 10

Deprecated: Using "_" as a class name is deprecated since 8.4 in /in/2mWrG on line 13

This example is for the _ deprecation (#15360) but this is a general issue in zend_assert_valid_class_name() - try enum bool {} and you get a fatal error about the class name. Also applies to class_alias errors:

<?php

class_alias( 'stdClass', '_' );
class_alias( 'stdClass', 'bool' );

produces

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

Fatal error: Cannot use 'bool' as class name as it is reserved in /in/cdB1P on line 4

PHP Version

PHP 8.2+

DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Sep 21, 2024
So that it is clearer what changes
DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Sep 21, 2024
Instead of always saying that a name is reserved or deprecated and
cannot/should not be used as a class name, take the usage into account and say
the name cannot be used as an enum name, trait name, etc. In the process, for
class names add a missing "a".
@DanielEScherzer
Copy link
Member Author

PR at #15977

DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Sep 21, 2024
Instead of always saying that a name is reserved or deprecated and
cannot/should not be used as a class name, take the usage into account and say
the name cannot be used as an enum name, trait name, etc. In the process, for
class names add a missing "a".
Girgias pushed a commit that referenced this issue Sep 22, 2024
So that it is clearer what changes
Girgias pushed a commit that referenced this issue Sep 22, 2024
Instead of always saying that a name is reserved or deprecated and
cannot/should not be used as a class name, take the usage into account and say
the name cannot be used as an enum name, trait name, etc. In the process, for
class names add a missing "a".
@nielsdos
Copy link
Member

Fixed by #15977

DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Sep 22, 2024
DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Sep 22, 2024
Girgias pushed a commit that referenced this issue Sep 23, 2024
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

2 participants