note 117858 added to function.function-exists

From: Date: Fri, 21 Aug 2015 15:55:26 +0000
Subject: note 117858 added to function.function-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-203408@lists.php.net to get a copy of this message
This is not going to go down as you might expect it should (even if you play smart and require/include_once): <?php if(function_exists('my_function')) { throw new Exception("'my_function' is already defined!"); } function my_function() { // Do the work here } ?> This, however does work: <?php if( ! function_exists('my_function')) { function my_function() { // Do the work here } } else { throw new Exception("'my_function' is already defined!"); } ?> Does it have anything to do with PHP parse/execute phases or global/local scope or those curly brackets or something else, I have no idea, but the latter ugly son works, while the former bombs out claiming that 'my_function' is already defined. Thought this might save someone a few minutes of debugging time... ---- Server IP: 72.52.91.14 Probable Submitter: 24.77.228.35 ---- Manual Page -- http://php.net/manual/en/function.function-exists.php Edit -- https://master.php.net/note/edit/117858 Del: integrated -- https://master.php.net/note/delete/117858/integrated Del: useless -- https://master.php.net/note/delete/117858/useless Del: bad code -- https://master.php.net/note/delete/117858/bad+code Del: spam -- https://master.php.net/note/delete/117858/spam Del: non-english -- https://master.php.net/note/delete/117858/non-english Del: in docs -- https://master.php.net/note/delete/117858/in+docs Del: other reasons-- https://master.php.net/note/delete/117858 Reject -- https://master.php.net/note/reject/117858 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203408) next »