Bug #64036 [NEW]: class_exists behavior while compile

From: Date: Mon, 21 Jan 2013 13:11:04 +0000
Subject: Bug #64036 [NEW]: class_exists behavior while compile
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-176150@lists.php.net to get a copy of this message
From: dirk dot gerigk at atraveo dot de Operating system: Linux PHP version: Irrelevant Package: *Compile Issues Bug Type: Bug Bug description:class_exists behavior while compile Description: ------------ PHP Version 5.3.9-ZS5.6.0 Is it an Complie Error or is it wanted in that way how it works! Please see the "Test Script" & "Actual Result". Only way to go around it (Force negative class_exists check and braces ): if(!class_exists('test')){ class test {} } For me it seems to be that the Compiler complies the hole file and declare directly the given class in the file. Only doesnt declare if the class defenition is within a function. But why can i change the result via 'test' | $t='test' ?? And see "Actual Result" as second question. Test script: --------------- //fileA.php - test is not included yet!! if(class_exists('test')) die('complier has included test'); class test {} //wont work - doesnt include the test class //fileB.php - test is not included yet!! if(class_exists($t='test')) die('wont never happen'); class test {} //works - includes test class Note: if u try that code with eval() both cases wont work! eval("\$t='test'; if(class_exists(\$t)){ die('complier has included test'); } class test {}"); Expected result: ---------------- In thing it is no really cool to always force "class definitions" in an negative "class_exists" check and then drop the class code within the {}. And i cannot really behind the diff. behavior on the eval() tryout. Please Note the add in "Actual Result". Actual result: -------------- //see "Test Script" and here is an crazy tryout on this issue: error_reporting(E_ALL); $t='test'; if(class_exists($t,false)){ echo ('complier has included '.$t);} class test {public $var='1';} class test {public $var='2';} What did you expect? Compile Error before running any Script??? So this: Fatal error: Cannot redeclare class test in C:\xampp\htdocs\js\in.php on line 5 Or this: complier has included test Fatal error: Cannot redeclare class test in C:\xampp\htdocs\js\in.php on line 5 Test it! I thing this behavior is a little bit wired. Maybe only for me ;) Thanks for the time. -- Edit bug report at https://bugs.php.net/bug.php?id=64036&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64036&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64036&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64036&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=64036&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=64036&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=64036&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=64036&r=needscript Try newer version: https://bugs.php.net/fix.php?id=64036&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=64036&r=support Expected behavior: https://bugs.php.net/fix.php?id=64036&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=64036&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=64036&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=64036&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64036&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=64036&r=dst IIS Stability: https://bugs.php.net/fix.php?id=64036&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=64036&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=64036&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=64036&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=64036&r=mysqlcfg

« previous php.bugs (#176150) next »