Why do you have to ommit the $ sign in this PHP class function ?

Boogyman

New member
Take a look at the class I copied from the PHP manual .. I am confused about something .


Ok for the function__construct of this PHP class , they typed "$this->foo = $foo;" Why didn't they include the $ sign after the $this-> to foo ?? Why didn't they type " $this-> $foo = $foo;" instead of "$this->foo = $foo;" ??? Doesn't every PHP variable have to contain the $sign in the beginning .. I got this class from the PHP manual

Even for the __string"() ... It returns $this->foo instead of $this->$foo ... why is that ??


<?php
// Declare a simple class
class TestClass
{
public $foo;

public function __construct($foo)
{
$this->foo = $foo;
}

public function __toString()
{
return $this->foo;
}
}

$class = new TestClass('Hello');
echo $class;
?>
 
Back
Top