Submit a Site

Understanding Object Oriented Programming in PHP

November 2nd, 2007 | Posted in Programming |
 

 

Trying to understand Object oriented PHP programming. Found this good explanation with examples at http://us.php.net/oop. Here is the code sample:

<?phpclass A
{
  function foo()
    {
      if (isset($this)) {
        echo '$this is defined (';
        echo get_class($this);
        echo ")\n";
      } else {
        echo "\$this is not defined.\n";
      }
    }
}

class B
{
  function bar()
    {
      A::foo();
    }
}

$a = new A();
$a->foo();
A::foo();
$b = new B();
$b->bar();
B::bar();

?>

THE RESULT:

$this is defined (a)
$this is not defined.
$this is defined (b)
$this is not defined.

 

Did You Like This Post?


Delicious button Stumbleupon



Post a Comment