Skip to content

Instantly share code, notes, and snippets.

@grzhan
Created May 12, 2013 12:46
Show Gist options
  • Save grzhan/5563444 to your computer and use it in GitHub Desktop.
Save grzhan/5563444 to your computer and use it in GitHub Desktop.
PHP Object Learning - Basic Concept - $this
<?php
class A {
function foo(){
if (isset($this)){
echo "\$this is defined (";
echo get_class($this);
echo ")\n";
} else {
echo "\$this is not defined";
}
}
}
class B {
function bar(){
// Note: the next line will issue a warning if E_STRICT is enabled.
A::foo();
}
}
function case1(){
echo "new A():<br>";
$objectA = new A();
$objectA->foo();
}
function case2(){
// Note: the next line will issue a warning if E_STRICT is enabled.
echo "<br>A::foo():";
A::foo();
}
function case3(){
$b = new B();
echo "<br>\$b->bar()";
$b->bar();
}
function case4(){
// Note: the next line will issue a warning if E_STRICT is enabled.
echo "B::bar();<br>";
B::bar();
}
case1();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment