Created
May 12, 2013 12:46
-
-
Save grzhan/5563444 to your computer and use it in GitHub Desktop.
PHP Object Learning - Basic Concept - $this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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