help please

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
silverbux
Forum Newbie
Posts: 9
Joined: Mon Aug 14, 2006 8:50 pm

help please

Post by silverbux »

is this possible?

$var = 'name';
$this->$$var = 'mark';

echo($this->name);
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Please read the forum descriptions before posting.

Moved to PHP Code.

And not to sound blunt, but have you even tried? There is nothing more fufilling than learning for yourself.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

no its not possible, you can't use this when something is not in object context.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

If that was inside a class it would work yes. You may need curly braces around the variable-variable. i.e.

$this->{$$var}
Post Reply