Page 1 of 1

Unaccessible function

Posted: Mon Jan 01, 2007 2:12 pm
by orbstra
Hey, I have a script with this type of architecture:

class Guava
->Function content()
-->Function content_method()

class Get
->function method()


the content_method() function is inside the content() function which is inside the Guava Class. I am sorry if this is confusing but ask me if you would like me to further explain the situation. Basically content_method() needs to be accessed by method() inside the Get Class, and because content_method() is inside a function inside a class, I am getting an error:
Fatal error: Call to undefined method Guava::content_method() in C:\Documents and Settings\Administrator\My Documents\My Projects\Web Projects\Guava\guav-includes\guav_library.php on line 229
Does anyone know how I can access the return value in content_method() from method()?

thanks, and sorry for the confusing explination

Posted: Mon Jan 01, 2007 2:19 pm
by feyd
When a method defines a function inside of it, the function will be given global scope, not become a method of the class.

Posted: Mon Jan 01, 2007 2:21 pm
by orbstra
How would I access the global scope in this case?

Posted: Mon Jan 01, 2007 2:39 pm
by feyd
Like you would any other function.

Posted: Mon Jan 01, 2007 2:57 pm
by volka
An example might help

Code: Select all

function globalFunctionABC() {
	echo 'abc ';
}

class Foo {
	function bar() {
		function globalFunctionXYZ() {
			echo 'xyz ';
		}
		echo 'bar ';
	}
}

$f = new Foo;
$f->bar();

globalFunctionABC();
globalFunctionXYZ(); // not a memeber of class Foo or an instance of Foo
// proof? Here you are
if ( method_exists($f, 'globalFunctionXYZ') ) {
	echo 'method exists ';
}
else {
	echo 'does not exist ';
}

$f->bar(); // <- Fatal error: Cannot redeclare globalfunctionxyz()