By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

Initialize Class with Constant

P: n/a
Hey,

is it possible to define a constant - lets say

define('CLASS_NAME','Shows');

and then initialize the Shows class with

$obj = new CLASS_NAME();

This obviously doesn't work, but how would i have to do it to make it
work?
Best regards,

Nikolai Onken

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Am Sun, 22 May 2005 10:42:56 -0700 schrieb ni***********@gmail.com:
Hey,

is it possible to define a constant - lets say

define('CLASS_NAME','Shows');

and then initialize the Shows class with

$obj = new CLASS_NAME();

This obviously doesn't work, but how would i have to do it to make it
work?
Best regards,

Nikolai Onken


Try it this way:

define('CLASS_NAME','Shows');
$classname = CLASS_NAME;
$obj = new $classname;
or with eval:

define('CLASS_NAME','Shows');
$obj = eval('new ' . CLASS_NAME . '();');

--
-------------------------------------------------------
Try this: SCA the Smart Class Archive for PHP
http://www.project-sca.org
-------------------------------------------------------

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.