Ok, here's what I'm trying to do.
I have a class. Inside the class I have a method that reads a text file.
In the text file I have a class name and a file name where that class is
defined. Now, I need to instantiate an object of that class, the problem
being that at the time I find out the class name and the file name, I'm
inside a method of another class. Well, let me just type up a little
example:
class MainClass {
$obj = null;
...
function init() {
$lines = file($some_file);
... // parsing
$kv = explode(":",$line);
$className = $kv[0];
$classFile = $kv[1];
// somehow define className that's in classFile
$this->obj = new $$className();
}
}
I don't remember exactly how it was I used a variable with new, I think
it was $$, but that's not the problem. The problem is that I don't need
to include the class definition file inside a function, I just need to
define a class using what's inside that file.
Taking the whole thing outside of the class definition is not going to
work - suppose I have many subclasses of this class, each with its own
file, then for every class I'd have to provide a separate function
outside the class definition to read the file.
Think of it as creating a tree of objects where children objects' class
names are taken out into a separate text file, so that at any time it
would be easy to change the set of succeeding children without changing
the parent class implementation.
Any ideas? :)
Lüph 2 3041
On Tue, 19 Oct 2004 04:07:11 GMT, Lüpher Cypher wrote: Taking the whole thing outside of the class definition is not going to work - suppose I have many subclasses of this class, each with its own file, then for every class I'd have to provide a separate function outside the class definition to read the file.
No, just include the class definition file anywhere, even inside the
function block. As PHP is parsed and compiled before it's executed, class
definitions are valid for whole program, regardless of where they are
defined.
Berislav
Berislav Lopac wrote: On Tue, 19 Oct 2004 04:07:11 GMT, Lüpher Cypher wrote:
Taking the whole thing outside of the class definition is not going to work - suppose I have many subclasses of this class, each with its own file, then for every class I'd have to provide a separate function outside the class definition to read the file.
No, just include the class definition file anywhere, even inside the function block. As PHP is parsed and compiled before it's executed, class definitions are valid for whole program, regardless of where they are defined.
Cool, I didn't know that. Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chuck Ritzke |
last post by:
I keep asking myself this question as I write class modules. What's the
best/smartest/most efficient way to send a large object back and forth to a
class module?
For example, say I have a data...
|
by: Tadeusz S. |
last post by:
Hello
In Pascal, I use constructions like that
var SomeVar = object
SomeVar2 = object
end;
end;
etc., so I could put my object into another
|
by: Nick Beenham |
last post by:
Can anyone give me a tip on how to pass a value from a
class to a windows form.
e.g. adding text to a textbox.
public class AnotherClass
{
//usual class code
public void AddText()
{
|
by: Typpo |
last post by:
Hi,
This question is somewhat basic. Is it possible to call a method in
frmMain, using another class? Here's a snippet:
partial class frmMain : Form
{
private void MessageThis(String text)...
|
by: rodchar |
last post by:
Hey all,
I'm trying to understand Master/Detail concepts in VB.NET. If I do a data
adapter fill for both customer and orders from Northwind where should that
dataset live?
What client is...
| |
by: D |
last post by:
I was reviewing these vb.net classes which deal with user logins, logouts,
cookies etc etc.
I noticed that in the Page_Load function of a user control the code calls
into another library like so...
|
by: rhamlin |
last post by:
I'm working on a class.
When instantiating I pass the variable name referencing the class (vw)
and the page object where the class will display (view).
In this class I create a DIV. I also...
|
by: Juha Nieminen |
last post by:
Assume I have a class Base, and then this:
struct Derived: public Base
{
AnotherClass member;
};
Also assume that I'm allocating an object of type 'Derived' with a
custom allocator and...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
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...
|
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,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |