Page 1 of 1

Correct way to define class variables

Posted: Wed Apr 25, 2007 12:00 am
by zorro2b
I am just starting to use classes with PHP 4.3.10. When I have error reporting on I get PHP notices for all class variable access.

For example, with this code:

Code: Select all

class Client
{
	var $clientId = -1;
	
	function Client($aClientId=-1)
	{
		$this->$clientId = $aClientId;
	}
...
I get a notice for the access of the clienId member in the constructor:
Notice: Undefined variable: clientId in /var/www/ozfl/common/classes/Client.php on line 12
What am I doing wrong? The class seems to work fine in spite of this.

Posted: Wed Apr 25, 2007 12:08 am
by alex.barylski
Drop the '$' on the variable just the 'this' needs it

$this->$some

Should be

$this->some