Skip to content

Check at compile time that a built-in class is not being aliased #9402

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

Merged
merged 1 commit into from
Aug 23, 2022

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Aug 22, 2022

If one tries to use such an alias as a type declaration the following error would be raised:
Fatal error: Cannot use 'int' as class name as it is reserved

If one tries to use such an alias as a type declaration the following error would be raised:
Fatal error: Cannot use 'int' as class name as it is reserved
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sensible

echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
eval("use $type as A; function foo$type(A \$v): A { return \$v; }");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of useless as all the above tests already Compile or ParseError.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because if I didn't add the early return in the C code when the use statement is created, it would create a non catchable fatal error.
But yes it is redundant :)

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the error message may be helpful, so it's an improvement. I wonder whether we should match the wording with https://3v4l.org/bl5dY; I do like "special class name" somehow, but there is ReflectionNamedType::isBuiltin(), so "built-in type" might be preferable.

@Girgias Girgias merged commit b9f7123 into php:master Aug 23, 2022
@Girgias Girgias deleted the use-builtin branch August 23, 2022 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants