From cdb7677b3801633cd0d3c55c322977749d0fb9b5 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Tue, 4 Jun 2024 17:24:19 +0100 Subject: [PATCH] Fix bug GH-14456: Attempting to initialize class with private constructor calls destructor Closes GH-14469 --- NEWS | 2 ++ Zend/tests/gh14456.phpt | 20 ++++++++++++++++++++ Zend/zend_object_handlers.c | 1 + 3 files changed, 23 insertions(+) create mode 100644 Zend/tests/gh14456.phpt diff --git a/NEWS b/NEWS index c78b4b1b6a8..be2ac4c104c 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 new file mode 100644 index 00000000000..e05edb1bc41 --- /dev/null +++ b/Zend/tests/gh14456.phpt @@ -0,0 +1,20 @@ +--TEST-- +GH-14456: Attempting to initialize class with private constructor calls destructor +--FILE-- +getMessage(), PHP_EOL; +} +?> +--EXPECT-- +Error: Call to private PrivateUser::__construct() from global scope diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 6a22156d181..58301da038c 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; } }