Merge branch 'PHP-8.3'

* PHP-8.3:
  Fix bug GH-14456: Attempting to initialize class with private constructor calls destructor
This commit is contained in:
Gina Peter Banyard 2024-06-06 15:51:47 +01:00
commit 3869a67468
No known key found for this signature in database
GPG Key ID: 3306078E3194AEBD
2 changed files with 21 additions and 0 deletions

20
Zend/tests/gh14456.phpt Normal file
View 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

View File

@ -1682,6 +1682,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;
}
}