How to create or define class in PHP at runtime and defin its attribute and functions? Is it possible?
A:
No.
You can however, add properties dynamically to particular instances.
Saying that eval permits this is like saying in Java you could, problematically, write a source file, compile it, and load it (or, for that matter in PHP you could include it). Sure, it's possible, but it's not actually part of the language.
Artefacto
2010-08-16 03:54:21
Well, actually, yes. But it's not recommendable.
zneak
2010-08-16 04:10:36
@zneak I've edited.
Artefacto
2010-08-16 04:31:44
A:
you could create a generic extendable class and use the magic __set() and __get() methods to dynamically add properties. no methods though, sorry.
Scott M.
2010-08-16 03:57:21
A:
basically
class A {
function B() {...}
}
everything in php is defined at runtime, so you should be fine with that. You can also try
include 'some.class.php';
"include" is the same as "eval" but somehow has a better image.
stereofrog
2010-08-16 07:24:40