Reply to Re: [PHP] Classe Variable

Your name:

Reply:


Posted by Jochem Maas on 04/20/05 21:04

Petar Nedyalkov wrote:
> On Wednesday 20 April 2005 13:29, marc serra wrote:
>
>>Hi,
>>i got a problem to write automaticaly varibles in classes.
>>
>>i got a simple object name test like this
>>
>>classes Test{
>> public $id;
>> public $text;
>>}
>>
>>i want to affect my value to my variable like this
>>$test = new Test

missing a ';' above

>>
>>$champ = id;

I think this should be:
$champ = 'id';

>>$valeur_champ = 4;
>>
>>$test->$champ = $valeur_champ;
>
>
> Just use $test->{$champ}
>
> ;-)

curlies are not required in this case (although they do allow more complex
expressions), the following works for me:

class T{public $id;}$t=new T;
$a="i";$b="d";$c="id";$v=4;$t->$c=$v;$t->{$b.$a}=5;
var_dump($c,$v,$t->$c,$t->id,$t->{$a.$b},$t);

>
>
>>my example is stupid i know but its just for an example.
>>in fact when i write $test->$champ = $valeur_champ; I want that php
>>execute $test->id = 4;
>>
>>can someone help me plz,
>>
>>Marc.
>
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация