From d87b3ca8f1dbcb395f2dfd6540483da7a0e5e15c Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Thu, 15 Jan 2015 16:34:14 +0100 Subject: Added the Php::Function class. This is an extension to the Php::Value class that can be used if you want to assign a std::function object to a Value. This is useful if you want to pass a C++ lambda to a PHP userspace function --- zend/object.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'zend/object.cpp') 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() { @@ -53,6 +53,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 -- cgit v1.2.3