Calling methods in the same class problem

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
afbase
Forum Contributor
Posts: 113
Joined: Tue Aug 15, 2006 1:29 pm
Location: SoCAL!!!!

Calling methods in the same class problem

Post by afbase »

ok, If I have a class, how do have method two call method one??? I just cut out a part of my class for example:

Code: Select all

class example{
var $bookval;

function set_bookval($number){
$this->bookval=$number;
}

function mysql_bookval($ticker){
	$url = "http://www.investor.reuters.wallst.com/stocks/Ratios.asp?rpc=66&ticker=".$ticker;
	$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_FAILONERROR, 1);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 3);
	$result = curl_exec($ch);
		curl_close($ch);
	$pattern='!Price to Book \(MRQ\)</span>\s*<span class="rb-company greycell">([^<]*)</span>!';
	preg_match($pattern,$result,$bookval);
	set_bookval($bookval[1]);
}
}

I get a mean little error if i try calling another method in the same class. Any ideas????
Fatal error: Call to undefined function set_bookval() in /home/clinton/hdd1/coldowl/project/stock/tests/stock_class.php on line 82
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

That should be $this->set_bookval($bookval[1]); instead...
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

the php manual loves you if you read him
Edit: if ($youLike) str_replace('him', 'her', $myPost);
Post Reply