note 38512 added to functions

From: Date: Thu, 25 Dec 2003 02:06:16 +0000
Subject: note 38512 added to functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-62439@lists.php.net to get a copy of this message
When building a class that has functions inside functions, the behavior and function scope of that inner function isn't quite what you would expect. This works. <? class blarg { function test() { function echo_hoorah() { echo 'hoorah!'; } } function another_test() { echo_hoorah(); } } $blarg = new blarg; $blarg->test(); // hoorah! ?> But this doesn't. <? class blarg { function test() { function echo_hoorah() { echo 'hoorah!'; } $this->another_test(); } function another_test() { echo_hoorah(); } } $blarg = new blarg; $blarg->test(); // hoorah! ?> But this doesn't. <? class blarg { function test() { function echo_hoorah() { echo 'hoorah!'; } $this->another_test(); } function another_test() { $this->echo_hoorah(); } } $blarg = new blarg; $blarg->test(); // Call to undefined function 'echo_hoorah'; ?> I would have expected the opposite. ---- Manual Page -- http://www.php.net/manual/en/functions.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38512 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38512&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38512&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62439) next »