From 865373be1f31341e7a43d774b21664080392788a Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Tue, 4 Jun 2024 17:24:19 +0100 Subject: [PATCH 1/2] Add test with incorrect behaviour --- Zend/tests/gh14456.phpt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Zend/tests/gh14456.phpt diff --git a/Zend/tests/gh14456.phpt b/Zend/tests/gh14456.phpt new file mode 100644 index 000000000000..b50820699ae1 --- /dev/null +++ b/Zend/tests/gh14456.phpt @@ -0,0 +1,23 @@ +--TEST-- +GH-14456: Attempting to initialize class with private constructor calls destructor +--FILE-- +getMessage(), PHP_EOL; +} +?> +--EXPECT-- +Destructor for PrivateUser +Error: Call to private PrivateUser::__construct() from global scope From 92d97a9731574bcd4d63b3872167210b1a582c39 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Tue, 4 Jun 2024 17:26:11 +0100 Subject: [PATCH 2/2] Fix bug GH-14456 --- NEWS | 2 ++ Zend/tests/gh14456.phpt | 1 - Zend/zend_object_handlers.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index cb22c9b63fce..c5e83ccc913f 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,8 @@ PHP NEWS when running on Apple Silicon). (Manuel Kress) . Fixed bug GH-14387 (Crash when stack walking in destructor of yielded from values during Generator->throw()). (Bob) + . Fixed bug GH-14456 (Attempting to initialize class with private constructor + calls destructor). (Girgias) - BCMatch: . Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0). (Girgias) diff --git a/Zend/tests/gh14456.phpt b/Zend/tests/gh14456.phpt index b50820699ae1..4f350c7fc3ad 100644 --- a/Zend/tests/gh14456.phpt +++ b/Zend/tests/gh14456.phpt @@ -19,5 +19,4 @@ try { } ?> --EXPECT-- -Destructor for PrivateUser Error: Call to private PrivateUser::__construct() from global scope diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 6a22156d181d..58301da038ce 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1622,6 +1622,7 @@ ZEND_API zend_function *zend_std_get_constructor(zend_object *zobj) /* {{{ */ if (UNEXPECTED(constructor->op_array.fn_flags & ZEND_ACC_PRIVATE) || UNEXPECTED(!zend_check_protected(zend_get_function_root_class(constructor), scope))) { zend_bad_constructor_call(constructor, scope); + zend_object_store_ctor_failed(zobj); constructor = NULL; } }