From 1bc84804cd515f876110d5dc075db76b11b2ab59 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. --- Zend/tests/gh16665_1.phpt | 8 ++++++++ Zend/tests/gh16665_2.phpt | 8 ++++++++ Zend/zend_compile.c | 4 ++++ 3 files changed, 20 insertions(+) create mode 100644 Zend/tests/gh16665_1.phpt create mode 100644 Zend/tests/gh16665_2.phpt diff --git a/Zend/tests/gh16665_1.phpt b/Zend/tests/gh16665_1.phpt new file mode 100644 index 0000000000000..5baa46a039121 --- /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 0000000000000..3b8ffd4c1e6b0 --- /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 73bc661cd40e3..ce8fa88dee3c0 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} };