How to run code upon class definition (not object instantiation)?

That would be impossible, yeah. Nothing gets called on class definition This concept is even sort of aggressively unsupported; try writing class foo { static function __construct() { echo "hi! "; } } and you'll get Fatal error: Constructor blah::__construct() cannot be static.

That would be impossible, yeah. Nothing gets called on class definition. This concept is even sort of aggressively unsupported; try writing class foo { static function __construct() { echo "hi!"; } } and you'll get Fatal error: Constructor blah::__construct() cannot be static.

Not exactly sure what your end goal is here. Perhaps you're looking for the ReflectionClass at run time? You can determine if a class exists and what the extended class is.

It also sounds like what you're aiming for is an object factory that keeps track of objects that are being used. Look up singletons, factory, and static member functions/variables concepts for those.As for this: class A { public function __construct() { print "A has been called"; } } if class B overrides the constructor, it's not going to call A's constructor. Ex: class B extends A { public function __construct() { print "B has been called"; // parent::__construct(); /// would print out A has been called } } However in code, you can check if B is an instance of A one of many ways: function doSomethingWithA(A $a).... function doSmoethingWithA($a) { if($a instanceof A) { // blah } } Don't know if that helps much.

That would actually be helpful if I wasn't already on that track. Thanks! I'm exploring other ways of doing what I need.

I'm building a database abstraction layer called Sqool, and its really nice for the user to be able to just create a single class then use it. The problem is that I only know an underlying "sqool class" (table) exists if someone has already instantiated at least one object. The way i'm planning on solving this is having the user create a function (with a standard name) that I can call if i'm not yet aware of the class.

If you're interested check out tinyurl. Com/o3tz2n – B T Aug 14 '09 at 21:51.

In Java, this is possible, by using a "java agent" which would register a java.lang.instrument. ClassFileTransformer with the JVM.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions