Page 1 of 1

Calling function B within function A in a class

Posted: Tue Feb 08, 2005 5:43 am
by anjanesh
I have a class with 2 functions : run() and display().
display() is to be called many times in run() function.

Code: Select all

function run()
 {
 display($something)
 }
function display($k)
 {
 ...
 }
I get the error :
Fatal error: Call to undefined function: display() in x:\xxx\xxx.php on line xx
I tried this->display($something) still same error.
This is the way it works in most OOP languages.

Using PHP 4.3.10 not 5

Any idea how to overcome this error ?
Thanks

Posted: Tue Feb 08, 2005 6:51 am
by JayBird
this works for me

Code: Select all

class test {
	function run() 
	{ 
		$something = "hello";
		test::display($something); 
	} 
	
	
	function display($k) 
	{ 
		echo $k;
	} 
	
}
	
$test = new test;

$test->run();
Take a look here for more information on the Scope Resolution Operator (::) http://de3.php.net/manual/en/keyword.pa ... otayim.php

Posted: Tue Feb 08, 2005 7:00 am
by anjanesh
Actually I knew abt this->display($something)
but now I know its $this->display($something)
Thanks