Discussion: variable
Afficher un message
Vieux 16/09/2007, 23h53   #10
Sanders Kaufman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: variable

Michael Fesser wrote:

> It's called a variable variable. As said - instead of accessing a
> variable directly, it's done by taking the name of the variable from
> _another_ string variable:


Oh, WOW!!! That is so cool.
I was kinda thinkin about doing something like that all hodge-podge with
"eval" statements, but figured it was too hair-brained.



> Usuallly it's considered bad style to use variable variables, in most
> cases there's a better way.


So... it is a little hair-brained, eh?
Still - I'll have some fun exploring that.


> But there's a similar thing that can be
> really ful - variable class names, i.e. the class name is stored in
> a variable:
>
> $foo = 'TMyClass';
> $bar = new $foo(); // creates an instance of the class TMyClass


Now I'm confused again.
Maybe I'm applying Java logic here or something.
Why doesn't that just create a new string containing, 'TMyClass'?
  Réponse avec citation
 
Page generated in 0,04579 seconds with 9 queries