note 30973 added to functions
| From: | gayard at ig dot com dot br | Date: | Fri, 04 Apr 2003 20:58:01 +0000 |
| Subject: | note 30973 added to functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46236@lists.php.net to get a copy of this message | ||
In PHP 4.3.0, I have found a bug in declaring functions within functions:
<?
function MyZero($x) {
function GreaterThanZero() { echo "Greater"; }
function LessThanZero() { echo "LessThan"; }
function EqualToZero() { echo "Equal"; }
if ($x > 0) GreaterThanZero();
else if ($x < 0) LessThanZero();
else EqualToZero();
}
MyZero(1);
MyZero(0);
MyZero(-1);
?>
The output is:
Greater
Fatal error: Cannot redeclare greaterthanzero() (previously declared in
/home/php/public_html/teste.php:4) in /home/php/public_html/teste.php on line 4
My advice is: declare functions like you did in C, that is one function at a time. This seems to
work fine.
--
http://www.php.net/manual/en/functions.php
http://master.php.net/manage/user-notes.php?action=edit+30973
http://master.php.net/manage/user-notes.php?action=delete+30973
http://master.php.net/manage/user-notes.php?action=reject+30973