Skip to content

Commit

Permalink
Fix GH-16665: \array and \callable should not be usable
Browse files Browse the repository at this point in the history
This list was initially introduced in 53a4038, but never included array or
callable. I suppose this is because int & friends are not actual tokens,
while array and callable are. This means it was never possible to do class
array, which is probably the reason this was overlooked.

Closes GH-16683.
  • Loading branch information
nielsdos committed Nov 6, 2024
1 parent bc4fa01 commit 96d1cd0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ PHP NEWS
- COM:
. Fix property access of PHP objects wrapped in variant. (cmb)

- Core:
. Fixed bug GH-16665 (\array and \callable should not be usable in
class_alias). (nielsdos)

- Curl:
. Added curl_multi_get_handles(). (timwolla)

Expand Down
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ PHP 8.5 UPGRADE NOTES
. bzcompress() now throws a ValueError when $work_factor is not between
0 and 250.

- Core:
. It is no longer possible to use "array" and "callable" as class alias names
in class_alias().

- LDAP:
. ldap_get_option() and ldap_set_option() now throw a ValueError when
passing an invalid option.
Expand Down
8 changes: 8 additions & 0 deletions Zend/tests/gh16665_1.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--TEST--
GH-16665 (\array should not be usable)
--FILE--
<?php
class_alias('stdClass', 'array');
?>
--EXPECTF--
Fatal error: Cannot use "array" as a class alias as it is reserved in %s on line %d
8 changes: 8 additions & 0 deletions Zend/tests/gh16665_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--TEST--
GH-16665 (\callable should not be usable)
--FILE--
<?php
class_alias('stdClass', 'callable');
?>
--EXPECTF--
Fatal error: Cannot use "callable" as a class alias as it is reserved in %s on line %d
4 changes: 4 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ static const struct reserved_class_name reserved_class_names[] = {
{ZEND_STRL("iterable")},
{ZEND_STRL("object")},
{ZEND_STRL("mixed")},
/* These are not usable as class names because they're proper tokens,
* but they are here for class aliases. */
{ZEND_STRL("array")},
{ZEND_STRL("callable")},
{NULL, 0}
};

Expand Down

0 comments on commit 96d1cd0

Please sign in to comment.