|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-02-07 10:16 UTC] knight_adi2000 at yahoo dot com
Description: ------------ --- From manual page: http://www.php.net/language.exceptions --- Notice the line if($throw_exception === 1) throw new Excepion('Exception thrown.<br>'); has Excepion NOT Exception word inside the code . This is not detected by the compiler when compiling the code , unless you set the value Int 1 as parameter, in order to make the function throw the error , and there is no class that i defined as Excepion , it can be replaced with any class not only Excepion (Not Exception) . Unless the function is made to throw an Exception, it does not detect that the actual object simply does NOT exist(in this case the object caled Excepion) . Be carefull with writing your code . Test script: --------------- <?php function test_compiler($throw_exception) { try { if($throw_exception === 1) throw new Excepion('Exception thrown.<br>'); } catch(Exception $exception) { echo "Error caught from test_compiler". $exception->getMessage(); } return 1; } echo test_compiler(2); ?> Expected result: ---------------- When i set the $throw_exception to other value than 1 integer type, the compiler should detect that the Excepion (NOT Exception ) object does NOT exist . Actual result: -------------- The compiler detects that the Excepion object DOES NOT exist ONLY IF the value is set to integer 1 , than and only than the compiler works right in this case . Please Php Staff take this into your atention . Thank you . PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Feb 05 08:00:02 2026 UTC |
PHP does not require types to be declared at compile time. Code like this is absolutely valid: main.php: <?php for ($i = 0; $i < 10; ++$i) { include "$i.php"; if ($throw == 1) throw new Excepion('Exception thrown.<br>'); } an then in 5.php or so: <?php class Excepion extends Exception {} Or there's __autoload ...