mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
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
This commit is contained in:
2
NEWS
2
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)
|
||||
|
||||
20
Zend/tests/gh14456.phpt
Normal file
20
Zend/tests/gh14456.phpt
Normal file
@@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
GH-14456: Attempting to initialize class with private constructor calls destructor
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class PrivateUser {
|
||||
private function __construct() {}
|
||||
public function __destruct() {
|
||||
echo 'Destructor for ', __CLASS__, PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
new PrivateUser();
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Error: Call to private PrivateUser::__construct() from global scope
|
||||
@@ -1686,6 +1686,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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user