note 32868 added to functions

From: Date: Mon, 09 Jun 2003 16:04:08 +0000
Subject: note 32868 added to functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-50035@lists.php.net to get a copy of this message
While PHP does allow you to define a function within another function, this feature doesn't work in at all the same way that it does in most other languages. The most common use of an inner subroutine that I've seen is to define a helper function which can't be seen from outside, and still has access to the outer subroutine's local variables. Like this: function a(){ function b(){ print $localVariable; } $localVariable = 10; b(); } In PHP, this will cause all sorts of problems. Calling a() won't print anything, since $localVariable hasn't been defined within b(), even though it is defined within a(). And calling a() twice will result in an error that you're trying to redefine b(). ---- Manual Page -- http://www.php.net/manual/en/functions.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32868 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32868&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32868&report=yes

« previous php.notes (#50035) next »