You are here: Re: Using a constant for abstraction? « All PHP « IT news, forums, messages
Re: Using a constant for abstraction?

Posted by sam on 11/16/05 23:57

> define(DATABASE_CLASS, MySQL_5_Database);

There is nothing wrong with this line


> $db = new DATABASE_CLASS($user, $pwd, $dbName);

Here php looks for class named DATABASE_CLASS because
of the new keyword and not for the contain of DATABASE_CLASS.

> Fatal error: Class 'DATABASE_CLASS' not found in
> C:\wwwroot\eclipse\workspace\cpim\index.php on line 21

That's why you get this error.

> Is there some way of using more C-style preprocessor substitution, to
> make something like this possible?

Yes:

define(DATABASE_CLASS, MySQL_5_Database);
..
..
..
$class_name = DATABASE_CLASS;

$db = new $class_name ($user, $pwd, $dbName);

Now, PHP knows that $class_name is a variable that contains the name of the
class.
That why it should work.

 

Navigation:

[Reply to this 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

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