Reply to Re: Using a constant for abstraction?

Your name:

Reply:


Posted by M. Trausch on 11/16/05 18:56

Gazornenplat wrote:
>
> DATABASE_CLASS is a constant
> DATABASE_CLASS(...) is a function which doesn't exist
>

*shrugs*. I was hoping that PHP's define() would work sort of something
along the lines of what the C preprocessor's #define does, so, while I
knew that, I didn't get the results that I'd quite expected. However,
see below...

>
> You could try something like:
>
> <?php
>
> define("DATABASE_CLASS", 'MySQL_5_Database("$user");');
> $user = "Ian";
>
> eval(DATABASE_CLASS);
>
> function MySQL_5_Database($user)
> {
> echo "Hello $user";
> }
> ?>

A slight adaptation to that made it work *perfectly*. I hadn't yet run
into eval(); (at least, before today). Thanks for the pointer! The way
I worked eval(); worked great, I just needed to know what it was that I
could do:

$dbClass = DATABASE_CLASS;
eval("\$db = new ${dbClass}(DATABASE_USER, DATABASE_PASS, DATABASE_NAME);");

(It's wrapped due to the e-mail client; not so in the actual code).

Thanks!
Mike

--
Strip the obvious trash from the header to send e-mail.

[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

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