|  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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: marco at tremani dot nl
New email:
PHP Version: OS:


 [2021-11-10 15:55 UTC] marco at tremani dot nl
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



    class a
        public function __toString()
            return '';

File: b.php

    <?php var_dump(class_exists('a'));

Expected result:
> php a.php

Actual result:
On PHP 7.4:

On PHP 8.0:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-10 16:01 UTC]
-Status: Open +Status: Duplicate
 [2021-11-10 16:01 UTC]
Duplicate of bug #79350. may be helpful as background ;)
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jan 27 09:05:54 2023 UTC