Skip to content

Commit 3869a67

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix bug GH-14456: Attempting to initialize class with private constructor calls destructor
2 parents 28cac94 + 7bab3a3 commit 3869a67

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Zend/tests/gh14456.phpt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-14456: Attempting to initialize class with private constructor calls destructor
3+
--FILE--
4+
<?php
5+
6+
class PrivateUser {
7+
private function __construct() {}
8+
public function __destruct() {
9+
echo 'Destructor for ', __CLASS__, PHP_EOL;
10+
}
11+
}
12+
13+
try {
14+
new PrivateUser();
15+
} catch (Throwable $e) {
16+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
17+
}
18+
?>
19+
--EXPECT--
20+
Error: Call to private PrivateUser::__construct() from global scope

Zend/zend_object_handlers.c

+1
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,7 @@ ZEND_API zend_function *zend_std_get_constructor(zend_object *zobj) /* {{{ */
16821682
if (UNEXPECTED(constructor->op_array.fn_flags & ZEND_ACC_PRIVATE)
16831683
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(constructor), scope))) {
16841684
zend_bad_constructor_call(constructor, scope);
1685+
zend_object_store_ctor_failed(zobj);
16851686
constructor = NULL;
16861687
}
16871688
}

0 commit comments

Comments
 (0)