note 114821 deleted from functions.user-defined by salathe

From: Date: Fri, 21 Nov 2014 14:57:00 +0000
Subject: note 114821 deleted from functions.user-defined by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-200986@lists.php.net to get a copy of this message
Note Submitter: webmaster at heathdale dot vic dot edu dot au ---- <?php // first run (function doesn't exist) $myfunc_exists; if (! $myfunc_exists) { function myfunc() { echo ('myfunc ran definition #1<br>'); } $myfunc_exists = true; } myfunc(); // echoes 'myfunc ran definition #1<br>' // second run (function already exists, so won't be redefined and won't cause error) // e.g. if the file containing the function got #included twice (it does happen) $myfunc_exists; if (! $myfunc_exists) { function myfunc() { echo ('myfunc ran definition #2<br>'); } $myfunc_exists = true; } myfunc(); // still echoes 'myfunc ran definition #1<br>' (not #2) ?>

« previous php.notes (#200986) next »