Can PHP Perform Magic Instantiation?
Posted
by Aiden Bell
on Stack Overflow
See other posts from Stack Overflow
or by Aiden Bell
Published on 2010-05-11T18:31:59Z
Indexed on
2010/05/11
18:34 UTC
Read the original article
Hit count: 262
Despite PHP being a pretty poor language and ad-hoc set of libraries ... of which the mix of functions and objects, random argument orders and generally ill-thought out semantics mean constant WTF moments....
... I will admit, it is quite fun to program in and is fairly ubiquitous. (waiting for Server-side JavaScript to flesh out though)
question:
Given a class class RandomName extends CommonAppBase {}
is there any way to automatically create an instance of any class extending CommonAppBase
without explicitly using new
?
As a rule there will only be one class definition per PHP file. And appending new RandomName()
to the end of all files is something I would like to eliminate. The extending class has no constructor; only CommonAppBase
's constructor is called.
Strange question, but would be nice if anyone knows a solution.
Thanks in advance, Aiden
(btw, my PHP version is 5.3.2) Please state version restrictions with any answer.
© Stack Overflow or respective owner