473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Initialize Class with Constant

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
1 2311
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Kyle | last post by:
Hi, Is it possible to initialize a constant memeber array in a class? I tried several syntax but all failed. class A { public: A(); ~A(); private:
3
by: Tony Johansson | last post by:
Hello!! Hello Experts! I'm right if I say that if I have attribute that is constant or attribute that is of reference type or attribute that is class type then I must use initialize list. ...
3
by: jut_bit_zx | last post by:
class A { public: A(); virtual ~A(){} .... private: int m_iarray; }
3
by: dpriver | last post by:
I have to initialize a huge constant array of structures(60000~100000), used as a lookup table , but it failed with System.InvalidProgramException when the items reach 18400. and if I change the...
4
by: bob | last post by:
Why doesn't c++ let me initialize static members like this: class MySound { static CSoundManager* g_pSoundManager = NULL; };
6
by: nik | last post by:
hello friends, a class having two const variables ,how can we initialize these variables
18
by: toton | last post by:
Hi, In C++ when I initialize an array it, also initializes the class that it contains, which calls the default constructor. However, I want to initialize the array only (i.e reserve the space) and...
9
by: subramanian | last post by:
I am a beginner in C++. Suppose I want to build a class: I have given below the starting code: class Date { int day, month, year; static Date default_date; };
3
by: Hank stalica | last post by:
So I have this class with a private data member: const Floor* const destFloor; I need to initialize f, which I'm trying to do in the constructor initializer list: Rider::Rider(const...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.