Reply to Re: variable

Your name:

Reply:


Posted by Michael Fesser on 09/16/07 22:41

..oO(Sanders Kaufman)

>Michael Fesser wrote:
>
>> But there's a similar thing that can be
>> really helpful - 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'?

Because PHP is not Java. ;)

In this case the name of the class is taken from the variable (notice
the parentheses after the variable name). The same can also be done with
functions, which is a common way to implement callback functions in PHP.

Micha

[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

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