Skip to content

Commit 7bab3a3

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix bug GH-14456: Attempting to initialize class with private constructor calls destructor
2 parents ee7d35c + cdb7677 commit 7bab3a3

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88
when running on Apple Silicon). (Manuel Kress)
99
. Fixed bug GH-14387 (Crash when stack walking in destructor of yielded from
1010
values during Generator->throw()). (Bob)
11+
. Fixed bug GH-14456 (Attempting to initialize class with private constructor
12+
calls destructor). (Girgias)
1113

1214
- BCMatch:
1315
. Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0). (Girgias)

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
@@ -1686,6 +1686,7 @@ ZEND_API zend_function *zend_std_get_constructor(zend_object *zobj) /* {{{ */
16861686
if (UNEXPECTED(constructor->op_array.fn_flags & ZEND_ACC_PRIVATE)
16871687
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(constructor), scope))) {
16881688
zend_bad_constructor_call(constructor, scope);
1689+
zend_object_store_ctor_failed(zobj);
16891690
constructor = NULL;
16901691
}
16911692
}

0 commit comments

Comments
 (0)