Solace Solace - 2 years ago 84
PHP Question

Can a variable named as `$something` be referred to by `someting`, that is without the dollar sign?

I am examining some PHP code written by somebody else, and they have basically named a variable


protected $text = null;

And then later in the same file, they are referring to it without the

$this->text[$name] = new Text($age, $house);

  1. I am a little intrigued. Is this even possible? Can a variable named
    with a
    concatenated with some word, be referred with only the
    part of the identifier other than

  2. If yes, does it imply something special or is it a simple reference
    to the variable?

PS: I don't think the code is faulty because it works =s

Answer Source

This code is not faulty it's because it is writen in Object Oriented PHP. When you declare an attribute in a php object, in that case $text, you can later in that same class refer to that attribute as $this->text.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download