Skip to content

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