zend_class_entry.create_object

php.internals

Brandon Fosdick

20 years ago
When registering a new class, what are the consequences of setting zend_class_entry.create_object = NULL? INIT_CLASS_ENTRY() defaults it to NULL, but the tutorial I'm looking at sets it to the address of a function immediately afterwards. My concern is that setting this allows the engine to call a constructor-like-function behind my back. I'd rather handle such things while handling calls to new(). Is that possible? Is it even a good idea? The tutorial code provides a function for zend_class_entry.create_object that returns a populated zend_object_value. Presumably that's a useful thing to do, and if I don't have a function there I would need to find some other means of supplying the zend_object_value to the engine. Can I do that in a new() handler? How?

Marcus Börger

20 years ago
Hello Brandon, create_object is your new handler that is supposed to deliver an empty object. You cannot have this NULL. The __construct part allows to define what the actual constructor does afterwards. Forcing __construct to be called is a bit more complicated but a bunch of exts already do so. Check out pdo on that. regards marcus Wednesday, May 3, 2006, 8:24:41 AM, you wrote:
> When registering a new class, what are the consequences of setting > zend_class_entry.create_object = NULL? INIT_CLASS_ENTRY() defaults it to > NULL, but the tutorial I'm looking at sets it to the address of a function immediately afterwards.
> My concern is that setting this allows the engine to call a > constructor-like-function behind my back. I'd rather handle such things > while handling calls to new(). Is that possible? Is it even a good idea?
> The tutorial code provides a function for zend_class_entry.create_object > that returns a populated zend_object_value. Presumably that's a useful > thing to do, and if I don't have a function there I would need to find > some other means of supplying the zend_object_value to the engine. Can I do that in a new() handler? How?
Best regards, Marcus