Correct way to define class variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zorro2b
Forum Newbie
Posts: 1
Joined: Tue Apr 24, 2007 11:52 pm

Correct way to define class variables

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Drop the '$' on the variable just the 'this' needs it

$this->$some

Should be

$this->some
Post Reply