Bug #81605 [Opn->Dup]: Regression in class loading order when __toString() is implemented
| From: | nikic@php.net | Date: | Wed, 10 Nov 2021 16:01:47 +0000 |
| Subject: | Bug #81605 [Opn->Dup]: Regression in class loading order when __toString() is implemented | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237669@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81605&edit=1
ID: 81605
Updated by: nikic@php.net
Reported by: marco at tremani dot nl
Summary: Regression in class loading order when __toString()
is implemented
-Status: Open
+Status: Duplicate
Type: Bug
Package: Unknown/Other Function
Operating System: Windows/Unix
PHP Version: 8.0.12
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #79350.
https://www.npopov.com/2021/10/20/Early-binding-in-PHP.html
may be helpful as background ;)
Previous Comments:
------------------------------------------------------------------------
[2021-11-10 15:55:39] marco at tremani dot nl
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 this bug report at https://bugs.php.net/bug.php?id=81605&edit=1