Re: Re: Object members dynamic access?

From: Date: Thu, 16 Aug 2001 00:47:27 +0000
Subject: Re: Re: Object members dynamic access?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-62923@lists.php.net to get a copy of this message
Hi, The code below is actually code to access an object's member. That's fine as long as you give the name of the member at the time you write the code. What I am interested is to know if the members name might be a variable, I mean not hardcoded but a variable useful for loops, etc. Thanks. Sean C. McCarthy SCI, S.L. (www.sci-spain.com) Cerel wrote: > > Try this : > > class foo { > var $var1="hello"; > var $var2="world"; > } > ... > ... > $fooinstance = new foo; > $vartest=$fooinstance->var1; > echo ($vartest); // should be 'hello' > > This should work, but i had no time to test this code. > > See you later > > Sean C. McCarthy <smccarthy@sci-spain.com> a écrit dans le message : > 3B7B1195.3BA38850@sci-spain.com... > > Hi All, > > > > I was wondering if it is possible to access dinamically to the members > > of a class. I mean to access like: > > > > ---------------------- > > class foo { > > var $bar; > > var $barbar; > > } > > > > .. > > .. > > > > $foo_instance = new foo; > > $somevar = $foo->$anothervar; > > ----------------------------- > > > > I now this doesn't work, and have searched the manual and haven't found > > anything on it. I doubt it since this is more or less the work of the > > Arrays and not the way a class should behave. Anyway any ideas? thanks > > in advance. > > > > Sean C. McCarthy > > SCI, S.L. (www.sci-spain.com) > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#62923) next »