|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-11-10 16:01 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2021-11-10 16:01 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 03:00:01 2025 UTC |
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)