Skip to content

Commit 96d1cd0

Browse files
committed
Fix GH-16665: \array and \callable should not be usable
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.
1 parent bc4fa01 commit 96d1cd0

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- COM:
66
. Fix property access of PHP objects wrapped in variant. (cmb)
77

8+
- Core:
9+
. Fixed bug GH-16665 (\array and \callable should not be usable in
10+
class_alias). (nielsdos)
11+
812
- Curl:
913
. Added curl_multi_get_handles(). (timwolla)
1014

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ PHP 8.5 UPGRADE NOTES
2525
. bzcompress() now throws a ValueError when $work_factor is not between
2626
0 and 250.
2727

28+
- Core:
29+
. It is no longer possible to use "array" and "callable" as class alias names
30+
in class_alias().
31+
2832
- LDAP:
2933
. ldap_get_option() and ldap_set_option() now throw a ValueError when
3034
passing an invalid option.

Zend/tests/gh16665_1.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
GH-16665 (\array should not be usable)
3+
--FILE--
4+
<?php
5+
class_alias('stdClass', 'array');
6+
?>
7+
--EXPECTF--
8+
Fatal error: Cannot use "array" as a class alias as it is reserved in %s on line %d

Zend/tests/gh16665_2.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
GH-16665 (\callable should not be usable)
3+
--FILE--
4+
<?php
5+
class_alias('stdClass', 'callable');
6+
?>
7+
--EXPECTF--
8+
Fatal error: Cannot use "callable" as a class alias as it is reserved in %s on line %d

Zend/zend_compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ static const struct reserved_class_name reserved_class_names[] = {
214214
{ZEND_STRL("iterable")},
215215
{ZEND_STRL("object")},
216216
{ZEND_STRL("mixed")},
217+
/* These are not usable as class names because they're proper tokens,
218+
* but they are here for class aliases. */
219+
{ZEND_STRL("array")},
220+
{ZEND_STRL("callable")},
217221
{NULL, 0}
218222
};
219223

0 commit comments

Comments
 (0)