From 96d1cd00b7ee686143e0f66319a4ea5e324b723b Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 2 Nov 2024 18:52:10 +0100 Subject: [PATCH] Fix GH-16665: \array and \callable should not be usable This list was initially introduced in 53a40386, 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. --- NEWS | 4 ++++ UPGRADING | 4 ++++ Zend/tests/gh16665_1.phpt | 8 ++++++++ Zend/tests/gh16665_2.phpt | 8 ++++++++ Zend/zend_compile.c | 4 ++++ 5 files changed, 28 insertions(+) create mode 100644 Zend/tests/gh16665_1.phpt create mode 100644 Zend/tests/gh16665_2.phpt diff --git a/NEWS b/NEWS index c59c9a967c4..a833bf4355e 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/UPGRADING b/UPGRADING index a336173ffd8..13e834f2610 100644 --- a/UPGRADING +++ b/UPGRADING @@ -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. diff --git a/Zend/tests/gh16665_1.phpt b/Zend/tests/gh16665_1.phpt new file mode 100644 index 00000000000..5baa46a0391 --- /dev/null +++ b/Zend/tests/gh16665_1.phpt @@ -0,0 +1,8 @@ +--TEST-- +GH-16665 (\array should not be usable) +--FILE-- + +--EXPECTF-- +Fatal error: Cannot use "array" as a class alias as it is reserved in %s on line %d diff --git a/Zend/tests/gh16665_2.phpt b/Zend/tests/gh16665_2.phpt new file mode 100644 index 00000000000..3b8ffd4c1e6 --- /dev/null +++ b/Zend/tests/gh16665_2.phpt @@ -0,0 +1,8 @@ +--TEST-- +GH-16665 (\callable should not be usable) +--FILE-- + +--EXPECTF-- +Fatal error: Cannot use "callable" as a class alias as it is reserved in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 73bc661cd40..ce8fa88dee3 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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} };