[SOLVED] if statement within classes.

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
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

[SOLVED] if statement within classes.

Post by phpScott »

has anyone else come across this befor or is it just me not coding correctlly within classes for php4. I know I should be using 5 but deploying on a machine I have no contorl over.

ex

Code: Select all

<?php
class someclass
{
   function someclass($num)
	 {
           if($this->checkSomething($num))
	     echo "found it";
		 else
		   echo "not found";
	 }
   function chechSomething($num)
	 {
	   //some query to check some number
		 if($someVal<0);
		   return true;
		 else
		   return false;
	 }
}

?>
The question is this. in the top if statement I just do a check for to see if the return value is true or false, pretty straigtforward but it didn't seem to work properly or inconsistantly when it did.
Solved it by doing.

Code: Select all

<?php
class someclass
{
   function someclass($num)
	 {
	   $found=$this->checkSomething($num);
           if($found)
	     echo "found it";
	   else
	     echo "not found";
	 }
   function chechSomething($num)
	 {
	   //some query to check some number
		 if($someVal<0);
		   return true;
		 else
		   return false;
	 }
}

?>

?>
where i returned the result to a variable then checked the variable.

any ideas why people?

thanks
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Did you try with:

Code: Select all

if ($this->checkSomething($num) === true)
Mac
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

dope!!!!! :oops: :oops: :oops:
that would work. Silly boy tricks are for kids
'smacks hand upside head'
Post Reply