Page 1 of 1

[SOLVED] if statement within classes.

Posted: Mon Oct 11, 2004 5:11 am
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

Posted: Mon Oct 11, 2004 5:16 am
by twigletmac
Did you try with:

Code: Select all

if ($this->checkSomething($num) === true)
Mac

Posted: Mon Oct 11, 2004 5:21 am
by phpScott
dope!!!!! :oops: :oops: :oops:
that would work. Silly boy tricks are for kids
'smacks hand upside head'