[php-src] Issue #7873: Adding __toString method to class defined below instantiation causes class to not be detected
| From: | pocallaghan | Date: | Mon, 03 Jan 2022 10:37:36 +0000 |
| Subject: | [php-src] Issue #7873: Adding __toString method to class defined below instantiation causes class to not be detected | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-238720@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7873
Author: pocallaghan
### Description
This is probably considered non-standard usage, but I stumbled over it by accident.
The following code:
```php
<?php
$foo = new Test;
var_dump($foo);
class Test
{
public function __toString()
{
return '';
}
}
```
Resulted in this output:
```
PHP Fatal error: Uncaught Error: Class "Test" not found in /private/tmp/foo.php:3
Stack trace:
#0 {main}
thrown in /private/tmp/foo.php on line 3
Fatal error: Uncaught Error: Class "Test" not found in /private/tmp/foo.php:3
Stack trace:
#0 {main}
thrown in /private/tmp/foo.php on line 3
```
But I expected this output instead:
```
object(Test)#1 (0) {
}
```
If you remove the __toString method from the class, the code functions as expected.
### PHP Version
8.1.1
### Operating System
_No response_