diff options
Diffstat (limited to 'zend/object.cpp')
-rw-r--r-- | zend/object.cpp | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/zend/object.cpp b/zend/object.cpp index 7da8339..e2345c1 100644 --- a/zend/object.cpp +++ b/zend/object.cpp @@ -13,7 +13,7 @@ namespace Php { /** * Constructor to create a new instance of a builtin class - * + * * @param name Name of the class to instantiate * @param base The C++ object to wrap */ @@ -36,26 +36,26 @@ Object::Object(const char *name, Base *base) : Value() // here because this function is called from C++ context, and zend_error() // would cause a longjmp() which does not clean up C++ objects created // by the extension). - auto *entry = zend_fetch_class(name, ::strlen(name), ZEND_FETCH_CLASS_SILENT TSRMLS_CC); + auto *entry = zend_fetch_class(zend_string_init(name, ::strlen(name), 0), ZEND_FETCH_CLASS_SILENT TSRMLS_CC); if (!entry) throw FatalError(std::string("Unknown class name ") + name); // construct an implementation (this will also set the implementation // member in the base object), this is a self-destructing object that // will be destructed when the last reference to it has been removed, // we already set the reference to zero - new ObjectImpl(entry, base, 0 TSRMLS_CC); + new ObjectImpl(entry, base, ClassImpl::objectHandlers(entry), 0 TSRMLS_CC); // now we can store it operator=(Value(base)); // install the object handlers - Z_OBJVAL_P(_val).handlers = ClassImpl::objectHandlers(entry); + Z_OBJ_P(_val)->handlers = ClassImpl::objectHandlers(entry); } } /** * Constructor in case the class entry is already known - * + * * @param entry Class entry * @param base The C++ object to wrap */ @@ -76,13 +76,10 @@ Object::Object(zend_class_entry *entry, Base *base) : Value() // member in the base object), this is a self-destructing object that // will be destructed when the last reference to it has been removed, // we already set the reference to zero - new ObjectImpl(entry, base, 0 TSRMLS_CC); + new ObjectImpl(entry, base, ClassImpl::objectHandlers(entry), 0 TSRMLS_CC); // now we can store it operator=(Value(base)); - - // install the object handlers - Z_OBJVAL_P(_val).handlers = ClassImpl::objectHandlers(entry); } } @@ -95,12 +92,12 @@ Object::Object(const Value &value) : Value() { // when a string is passed in, we are going to make a new instance of the // passed in string - if (value.isString()) + if (value.isString()) { // instantiate the object if (instantiate(value)) call("__construct"); } - else + else { // this simply copies the other object operator=(value); @@ -121,23 +118,23 @@ bool Object::instantiate(const char *name) // here because this function is called from C++ context, and zend_error() // would cause a longjmp() which does not clean up C++ objects created // by the extension). - auto *entry = zend_fetch_class(name, ::strlen(name), ZEND_FETCH_CLASS_SILENT TSRMLS_CC); + auto *entry = zend_fetch_class(zend_string_init(name, ::strlen(name), 0), ZEND_FETCH_CLASS_SILENT TSRMLS_CC); if (!entry) throw FatalError(std::string("Unknown class name ") + name); // initiate the zval (which was already allocated in the base constructor) object_init_ex(_val, entry); - + // @todo should we call methods like allocating hashtables, copying and // initializing properties, et cetera????? In all example you always // see such complicated and next-to-impossible-to-understand // sequences of functions being called, but this object_init_ex // also seems to work... - - // @todo is this a memory leak? the base class first initializes a stdClass, + + // @todo is this a memory leak? the base class first initializes a stdClass, // and then we overwrite it with a specific class - + // return whether there is a __construct function - return zend_hash_exists(&entry->function_table, "__construct", 12); + return zend_hash_exists(&entry->function_table, zend_string_init("__construct", 12, 1)); } /** |