robue-a7119895
robue-a7119895

Reputation: 816

How to find get the name of a variable, of class instance inside the class.

I don't really think this is possibly, but who know I may get surprised.

There is no way to explain it, unless I get into the code fast.

class foo
{
   static function __callStatic($func, $arg)
   {
       //some magic here. 
   }
} 



  $foo = foo::bar(); 
  $bar = foo::bar();
  $x   = foo::bar();

here is my expected output.

  echo $foo;  // foo
  echo $bar;  // bar
  echo $x;    // x

Upvotes: 0

Views: 42

Answers (1)

bitWorking
bitWorking

Reputation: 12655

The variable is not present at that time. Only after the method call.

Test it:

class foo
{
   static function __callStatic($func, $arg)
   {
       print_r($GLOBALS);
   }
}

But why you need the var name?

Upvotes: 1

Related Questions