[php-src] Issue #14456: Attempting to initialize class with private constructor calls destructor
| From: | Girgias | Date: | Mon, 03 Jun 2024 15:47:40 +0000 |
| Subject: | [php-src] Issue #14456: Attempting to initialize class with private constructor calls destructor | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247021@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/14456
Author: Girgias
### Description
Found while working on #14440
The following code:
```php
<?php
class PrivateUser {
private function __construct() {
return new stdClass();
}
public function __destruct() {
echo 'Destructor for ', __CLASS__, PHP_EOL;
}
}
new PrivateUser();
```
Resulted in this output:
```
Destructor for PrivateUser
Fatal error: Uncaught Error: Call to private PrivateUser::__construct() from global scope in
/in/EF0hE:12
Stack trace:
#0 {main}
thrown in /in/EF0hE on line 12
```
But I expected this output instead:
```
Fatal error: Uncaught Error: Call to private PrivateUser::__construct() from global scope in
/in/EF0hE:12
Stack trace:
#0 {main}
thrown in /in/EF0hE on line 12
```
### PHP Version
master
### Operating System
_No response_