Hello.
I have managed porting my Zend1 objects to the new object structure and I have
some ideas or doubts I want to share:
Properties
-----------
The "add_property_*" function pool updates zval->value->obj->properties
(Z_OBJPROP_P), while now the correct HastTable to update is in
Z_OBJ_P(zval)->properties.
So I created a new set of functions (temporarily) named "add_objprop_*" that
updates the right HashTable, and I created a macro
#define add_property add_objprop
in case ZEND_ENGINE_2 should be defined inside my files.
It seems to work fine.
What will be the policy for properties in the future? Will be a separate set
of functions for the new object or will the "add_property_*" set be modified?
Constructor
-------------
Furthermore, my object had no costructor with the new model and there seems
not to be an API function to assign constructors. I used this little
function:
ZEND_API int set_constructor(zend_class_entry ** class_entry, char *
constructor_name) {
/*
* I use a zend_op_array because
* I cannot figure out how to populate a (zend_function *)
* otherwise ...
*/
zend_op_array * func_method;
if (zend_hash_find(
&(*class_entry)->function_table,
constructor_name,
strlen(constructor_name) + 1,
(void **) &func_method) == FAILURE) {
return FAILURE;
}
(*class_entry)->constructor = (zend_function *) func_method;
return SUCCESS;
}
and this function should be called from the MINIT function this way:
// an_object
INIT_OVERLOADED_CLASS_ENTRY
(ce,
"an_object",
php_an_object_class_functions,
NULL, NULL, NULL);
an_object_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL
TSRMLS_CC);
#ifdef ZEND_ENGINE_2
set_constructor(&an_object_class_entry, "scobject");
#endif
Constructor return value
---------------------------
I used before a this syntax to return value from constructors.
SEPARATE_ZVAL(&zval); \
*return_value = *zval; \
FREE_ZVAL(zval);
now I have noticed I should use this:
*return_value = *zval;
zval_copy_ctor(return_value);
I have some more function for dealing with objects. If someone is interested I
cand send it outside the list.
Regards,
Stefano
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php