Learning PHP and MySQL

Example 05-20 Using the -> operator to call hypnotize

<?php
class  Hypnotic_Cat  extends  Cat  {
  
//  Constructor
  
function  Hypnotic_Cat()  {
  }

  
//  This  is  meant  to  be  called  statically function  
  
hypnotize()  {
    
//detects  that  the  function  is  being  called  statically
    //since  a  static  call  doesn’t  have  an  object  to  point  to 
    
if  ($this  ==  null)
      echo  (
"All  cats  are  hypnotized.");
    else
    
{
      
echo  ("The  cat  was  hypnotized.");
      return;
    
}
  }
}

//  Hypnotize  all  cats
Hypnotic_Cat::hypnotize();

$hypnotic_cat  =  new  Hypnotic_Cat();
//  Does  nothing
$hypnotic_cat->hypnotize();
?>

Posted by on 08/03 at 08:26 AM

Next entry: Example 05-21 Referencing the $some_variable

Previous entry: Example 05-19 Calling the constructor of the parent class

<< Back to main