Advertisement
Guest User

get_defined_vars is inconsistent with $this

a guest
Jun 17th, 2010
1,522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. class Test
  4. {
  5.     public $var = 4;
  6.  
  7.     public function doStuff() {
  8.         $this->var = 4;
  9.     }
  10.     public function testNoThis() {
  11.         echo __METHOD__ . PHP_EOL;
  12.         var_dump(array_keys(get_defined_vars()));
  13.     }
  14.     public function testThisGet() {
  15.         echo __METHOD__ . PHP_EOL;
  16.         var_dump(array_keys(get_defined_vars()));
  17.         $this->var;
  18.     }
  19.     public function testThisSet() {
  20.         echo __METHOD__ . PHP_EOL;
  21.         var_dump(array_keys(get_defined_vars()));
  22.         $this->var = 4;
  23.     }
  24.  
  25.     public function testThisCall() {
  26.         echo __METHOD__ . PHP_EOL;
  27.         var_dump(array_keys(get_defined_vars()));
  28.         $this->doStuff();
  29.     }
  30.  
  31.     public function testThisUse() {
  32.         echo __METHOD__ . PHP_EOL;
  33.         var_dump(array_keys(get_defined_vars()));
  34.         $foo = $this;
  35.     }
  36. }
  37.  
  38. $t = new Test();
  39. $t->testNoThis();
  40. $t->testThisGet();
  41. $t->testThisSet();
  42. $t->testThisCall();
  43. $t->testThisUse();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement