Advertisement
Shishire

PHP special cases $this->

Sep 19th, 2012
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2.  
  3. class A
  4. {
  5.     public function foo()
  6.     {
  7.         var_dump('FOO');
  8.     }
  9. }
  10.  
  11. class B
  12. {
  13.     public function foo()
  14.     {
  15.         var_dump('BAR');
  16.     }
  17.     public function destroyTheUniverse()
  18.     {
  19.         $that = null;
  20.         $that =& $this;
  21.         var_dump($that, $this);
  22.         $a = new A();
  23.         $that = $a;
  24.         var_dump($that, $this);
  25.         $this->foo();
  26.         $that->foo();
  27.     }
  28. }
  29.  
  30. $b = new B();
  31. $b->destroyTheUniverse();
  32.  
  33. /* Output:
  34.  
  35. object(B)#1 (0) {
  36. }
  37. object(B)#1 (0) {
  38. }
  39. object(A)#2 (0) {
  40. }
  41. object(A)#2 (0) {
  42. }
  43. string(3) "BAR"
  44. string(3) "FOO"
  45. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement