diff --git a/NEWS b/NEWS index cb22c9b63fce1..c5e83ccc913f5 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 0000000000000..4f350c7fc3ad9 --- /dev/null +++ b/Zend/tests/gh14456.phpt @@ -0,0 +1,22 @@ +--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 6a22156d181d3..58301da038ce0 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; } }