note 21150 added to functions
| From: | bishop@php.net | Date: | Tue, 30 Apr 2002 23:54:55 +0000 |
| Subject: | note 21150 added to functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-30032@lists.php.net to get a copy of this message | ||
Consider:
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:
function a() {
if ( ! function_exists('b') ) {
function b() {
echo 'I am b';
}
}
echo 'I am a';
}
--
http://www.php.net/manual/en/functions.php
http://master.php.net/manage/user-notes.php?action=edit+21150
http://master.php.net/manage/user-notes.php?action=delete+21150
http://master.php.net/manage/user-notes.php?action=reject+21150