note 113852 added to function.class-exists

From: Date: Mon, 09 Dec 2013 14:43:25 +0000
Subject: note 113852 added to function.class-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-197886@lists.php.net to get a copy of this message
Hi guys! Be careful and don't forget about second boolean argument $autoload (TRUE by default) when check exists class after spl_autoload_register. Propose short example file second.php <?php class Second {} ?> file index.php <?php class First { function first($class, $bool) { spl_autoload_register( function($class) { require strtolower($class) . '.php'; }); echo class_exists($class, $bool)?'Exist!!!!':'Not exist!'; } } new First($class = 'Second', $bool = true); //Exist!!!! new First($class = 'Second', $bool = false); //Not exist! ?> Because __autoload executing much earlier than boolean returned, imho.. ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/function.class-exists.php Edit -- https://master.php.net/note/edit/113852 Del: integrated -- https://master.php.net/note/delete/113852/integrated Del: useless -- https://master.php.net/note/delete/113852/useless Del: bad code -- https://master.php.net/note/delete/113852/bad+code Del: spam -- https://master.php.net/note/delete/113852/spam Del: non-english -- https://master.php.net/note/delete/113852/non-english Del: in docs -- https://master.php.net/note/delete/113852/in+docs Del: other reasons-- https://master.php.net/note/delete/113852 Reject -- https://master.php.net/note/reject/113852 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197886) next »