Solace Solace - 12 days ago 4x
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


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.