Bug #81605 [NEW]: Regression in class loading order when __toString() is implemented
| From: | marco at tremani dot nl | Date: | Wed, 10 Nov 2021 15:55:39 +0000 |
| Subject: | Bug #81605 [NEW]: Regression in class loading order when __toString() is implemented | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-237668@lists.php.net to get a copy of this message | ||
From: marco at tremani dot nl
Operating system: Windows/Unix
PHP version: 8.0.12
Package: Unknown/Other Function
Bug Type: Bug
Bug description:Regression in class loading order when __toString() is implemented
Description:
------------
I'm not sure if this can be called a bug, unexpected or undefined
behavior - but behavior for the test case below changed in PHP 8.0.
The file below "a.php" implements this pattern: 1. include another file
"b.php". 2. declare a class. If that class contains a method
"__toString()", the class won't be available yet in b.php. I don't know
if this is the direct cause or merely a symptom of compiler behavior.
The example is a bit contrived but it demonstrates the changed behavior
clearly. It was encountered and extracted when upgrading a legacy php
library (nusoap).
Test script:
---------------
File: a.php
```
<?php
include('b.php');
class a
{
public function __toString()
{
return '';
}
}
```
File: b.php
```
<?php var_dump(class_exists('a'));
```
Expected result:
----------------
> php a.php
bool(true)
Actual result:
--------------
On PHP 7.4:
bool(true)
On PHP 8.0:
bool(false)
--
Edit bug report at https://bugs.php.net/bug.php?id=81605&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81605&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81605&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81605&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81605&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81605&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81605&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81605&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81605&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81605&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81605&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81605&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81605&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81605&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81605&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81605&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81605&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81605&r=mysqlcfg