mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
Fix bug GH-14456: Attempting to initialize class with private constructor calls destructor
Closes GH-14469
This commit is contained in:
parent
86b93bc479
commit
cdb7677b38
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
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user