Class , not class.
Posted on 2005-02-13 16:14:16 EET.
While MidgardRocks class was already initialized and declared with all its members I found this class very unstable and ( frankly speaking ) far from being usefull. I must say *FAR FROM*. Why? Zend extensions idea is good , not great , but good. You can initialize module, define globals , define classes and almost anything You would like to define.
When class is registered it is stored in CG globals HasHTable, so it is available at any time while module is loaded. What about members? You can add class' members by using one of few zend_hash_add_*** internal functions, by adding members ( object's properties ) to zend_class_entry->default_properties.
OK, where is the problem?
When You add members to class while module is initialized, you should mostly use EXACTLY the same functions which are used and defined in zend_compile.c. This simply means that all data and memory allocated should be freed when request shutdown is called. Got the point? You can not add and define class' members once , cause zend needs to destroy these data. This is not wierd when you think about calssess which are defined on PHP level.
Start request, define classess , methods , members and while request is ended , free them all.
Real nightmare from extension point of view.
What makes me "funny" is the fact that class members are destroyed, while class itself is not! It doesn't matter how you define members , and which zend_hash_xxx function will be used.
The most important thing. We need real class constructor. We need object to be initialized with all properties.
We need to extend classes with all parent's properties. I think that we could use some get() method which could be
real class constructor( If Zend knows about such thing as class constructor :/ ) .
What is also interesting. Initialized objects ( think about Zend ) are mostly initialized with 'return_value' internally used by Zend. It looks like no one documented the fact that one may use 'this_ptr' instead of returned value to get
PHP's syntax like $art = new Article();.
What do we need now to make MgdSchema being very usefull with Zend ( The most difficult midgard module to be created IMO )? Looks like we need some kind of "caching" feature to initialize classes only when theses should be used. They can be defined and registered , but empty as long as you will need to use them. And we need to make this during request time. This is bad , but still far more better and faster then define classes on PHP level.
At least we do not waste time which is needed to parse PHP code.