|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81224 Failed to load a class with '__toString' in required script
Submitted: 2021-07-05 15:46 UTC Modified: 2021-07-23 09:30 UTC
From: wxiaoguang at gmail dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 8.0.8 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: wxiaoguang at gmail dot com
New email:
PHP Version: OS:


 [2021-07-05 15:46 UTC] wxiaoguang at gmail dot com
PHP 7 can run these scripts correctly.

PHP 8 reports error if the class has a `__toString` method.

Test script:
require 'b.php';

class C
    // with this __toString method, 'b.php' can not find clas C
    public function __toString() { return ''; }

function test()
    return new C();


Expected result:
Script can run without error.

Actual result:
PHP Fatal error:  Uncaught Error: Class "C" not found in /home/test/a.php:12
Stack trace:
#0 /home/test/b.php(2): test()
#1 /home/test/a.php(2): require('/home/test/')
#2 {main}
  thrown in /home/test/a.php on line 12


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-23 08:51 UTC]
-Status: Open +Status: Verified
 [2021-07-23 08:51 UTC]
 [2021-07-23 09:30 UTC]
-Status: Verified +Status: Duplicate
 [2021-07-23 09:30 UTC]
Duplicate of bug #79350. __toString() prevents early binding since PHP 8.0.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 04:01:30 2024 UTC