# zend_register_class() overwrites ce->create_object with parent_ce->create_object?

- Thread: https://externals.io/message/49557
- Original archive: https://news-web.php.net/php.internals/49557
- Started by Michael Wallner on 2010-09-02T16:04:12+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #49557 — Michael Wallner — 2010-09-02T16:04:12+00:00

URL: https://externals.io/message/49557#49557

If I define a descendant class, I *obviously* know what create_object should
do, as this should only effect internal classes.  So could anybody please
explain to me why the parent's create_object is enforced?

It causes to write hacks like:

---8<---
zend_class_entry *ce;
zend_object_value (*__create_object)(zend_class_entry *ce TSRMLS_DC);

INIT_CLASS_ENTRY(ce, "classname", php_my_method_entry);
ce.create_object = php_my_object_new;
/* hack starts here */
__create_object = parent_ce->create_object;
parent_ce->create_object = php_my_object_new;
php_my_class_entry = zend_register_internal_class_ex(&ce, parent_ce, `NULL` TSRMLS_CC);
parent->create_object = __create_object;
--->8---

If this limitation is there without a really good reason, I'd like to get rid of it.

Thanks,
Mike

---

## #49558 — Etienne Kneuss — 2010-09-02T17:29:04+00:00

URL: https://externals.io/message/49557#49558 · In reply to: #49557

> If I define a descendant class, I *obviously* know what create_object should
> do, as this should only effect internal classes.  So could anybody please
> explain to me why the parent's create_object is enforced?
> 
> It causes to write hacks like:
> 
> ---8<---
> zend_class_entry *ce;
> zend_object_value (*__create_object)(zend_class_entry *ce TSRMLS_DC);
> 
> INIT_CLASS_ENTRY(ce, "classname", php_my_method_entry);
> ce.create_object = php_my_object_new;
> /* hack starts here */
> __create_object = parent_ce->create_object;
> parent_ce->create_object = php_my_object_new;
> php_my_class_entry = zend_register_internal_class_ex(&ce, parent_ce, `NULL` TSRMLS_CC);
> parent->create_object = __create_object;
> --->8---

Why can't you simply overwrite it afterwards? Just like it's done in
SPL:

http://php-og.mgdm.net/opengrok/xref/PHP_5_3/ext/spl/spl_functions.c#41

Best,

> 
> If this limitation is there without a really good reason, I'd like to get rid of it.
> 
> Thanks,
> Mike
> 
> -- 
> 
> 
> 

-- 
Etienne Kneuss

---

## #49559 — Michael Wallner — 2010-09-03T07:56:36+00:00

URL: https://externals.io/message/49557#49559 · In reply to: #49558

> Why can't you simply overwrite it afterwards? Just like it's done in
> SPL:
>
> http://php-og.mgdm.net/opengrok/xref/PHP_5_3/ext/spl/spl_functions.c#41

doh! Thanks for pointing a lame duck to the obvious. :)

Mike
