note 41225 added to language.variables.scope
| From: | Godar at rn2 dot php dot net | Date: | Sat, 03 Apr 2004 10:08:33 +0000 |
| Subject: | note 41225 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67544@lists.php.net to get a copy of this message | ||
I am trying to make a weather web service using the nuSOAP and XML libs. I have created a class and
worked on it for a while and I am stuck on parsing the xml file into the new object. I am trying to
make a method in a class called readXML($file) however the XML parser wants param's to some
local functions so I nested them. This works fine but I don't have access to the outer class
vars/methods or outer function vars. I have created a test class to illistrate my situation.
Code:
class foo {
// this var needs to be accessed by nested function "nbar()"
var $i;
// Constructor
function foo() {
$this->i = 100;
}
// this function needs to be accessed by nested function "nbar()"
function roo() {
echo "function roo()";
}
// bar test funct access to class vars from nested class functions.
function bar() {
$j = 12;
function nbar() {
global $j;
// Cannot access $j var from herer "global" does not work
echo "(nbar) j = ".$j." <br>\n";
$j++;
// Cannot access var $i either.
echo "(nbar) i = ".$this->i." <br>\n";
//Access function roo() from here ???? des not work.
//$this->roo(); // Generates error (how do I bring it into scope of this function)
}
nbar(); // No vars can be passed to the func. (one of the constraints)
echo "(bar) j = ".$j."<br>\n";
}
}
The comments explain where the problems lie. Any help would be greatly appreciated.
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41225
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41225&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41225&report=yes
Search -- http://master.php.net/manage/user-notes.php