0

Does PHP have an option to mark a variable as an instance variable or class variable or local variable inside a class?

Ruby has the following options:

Local variable   ->  myvar
Instance variable->  @myvar 
Class variable   ->  @@myvar 

Is there any such option in PHP other than this lengthy $myvar, $this->myvar and self::$myvar?

I asked like this because I'm from ruby on rails background. There it was so easy to handle variables like as i gave above. In PHP the variable handling style didn't felt so handy. So I referred a docs a lot times. But didn't find any so I asked if I missed any such option in the docs and anyone else may have noticed it.

Prashanth Shyamprasad
  • 827
  • 2
  • 17
  • 39

2 Answers2

4

No, there are no such options in PHP.

Vlad Preda
  • 9,780
  • 7
  • 36
  • 63
2
$this->variable; //class var
ClassName::variable; //static var
$variable; //local var

Other than the above there is no other way to declare a variable (unless you want to use constants define('VARIABLE', "some constant");)

Naftali
  • 144,921
  • 39
  • 244
  • 303