diff options
Diffstat (limited to 'zend/object.cpp')
-rw-r--r-- | zend/object.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/zend/object.cpp b/zend/object.cpp index 22431fe..7da8339 100644 --- a/zend/object.cpp +++ b/zend/object.cpp @@ -15,7 +15,7 @@ namespace Php { * Constructor to create a new instance of a builtin class * * @param name Name of the class to instantiate - * @param base Implementation of the class + * @param base The C++ object to wrap */ Object::Object(const char *name, Base *base) : Value() { @@ -54,6 +54,39 @@ Object::Object(const char *name, Base *base) : Value() } /** + * Constructor in case the class entry is already known + * + * @param entry Class entry + * @param base The C++ object to wrap + */ +Object::Object(zend_class_entry *entry, Base *base) : Value() +{ + // does the object already have a handle? + if (base->implementation()) + { + // the object is already instantiated, we can assign it to this object + operator=(Value(base)); + } + else + { + // we need the tsrm_ls variable + TSRMLS_FETCH(); + + // 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); + + // now we can store it + operator=(Value(base)); + + // install the object handlers + Z_OBJVAL_P(_val).handlers = ClassImpl::objectHandlers(entry); + } +} + +/** * Copy constructor is valid if the passed in object is also an object, * or when it is a string holding a classname * @param that An other object |