note 21150 deleted from language.functions by googleguy

From: Date: Mon, 24 Aug 2015 10:00:37 +0000
Subject: note 21150 deleted from language.functions by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203430@lists.php.net to get a copy of this message
Note Submitter: bishop ---- Consider: <?php function a() { function b() { echo 'I am b'; } echo 'I am a'; } a(); a(); ?> As you might NOT expect, the second call to a() fails with a "Cannot redeclare b()" error. This behaviour is correct, insofar as PHP doesn't "allow functions to be redefined." A work around: <?php function a() { if ( ! function_exists('b') ) { function b() { echo 'I am b'; } } echo 'I am a'; } ?>

« previous php.notes (#203430) next »