php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81605 Regression in class loading order when __toString() is implemented
Submitted: 2021-11-10 15:55 UTC Modified: 2021-11-10 16:01 UTC
From: marco at tremani dot nl Assigned:
Status: Duplicate Package: Unknown/Other Function
PHP Version: 8.0.12 OS: Windows/Unix
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: marco at tremani dot nl
New email:
PHP Version: OS:

 

 [2021-11-10 15:55 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-10 16:01 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2021-11-10 16:01 UTC] nikic@php.net
Duplicate of bug #79350.

https://www.npopov.com/2021/10/20/Early-binding-in-PHP.html may be helpful as background ;)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC