summaryrefslogtreecommitdiff
path: root/zend/object.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-15 16:34:14 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-15 16:34:14 +0100
commitd87b3ca8f1dbcb395f2dfd6540483da7a0e5e15c (patch)
tree6dd3179162d5cecc474fc9028039bd757f6df04b /zend/object.cpp
parentd8fe9239959dfeae11daa5de70126e30119d3b75 (diff)
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
Diffstat (limited to 'zend/object.cpp')
-rw-r--r--zend/object.cpp35
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