Calling function B within function A in a class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Calling function B within function A in a class

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Actually I knew abt this->display($something)
but now I know its $this->display($something)
Thanks
Post Reply