summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Otto <martijn.otto@copernica.com>2015-06-19 10:14:06 +0200
committerMartijn Otto <martijn.otto@copernica.com>2015-06-19 10:14:06 +0200
commit01990e0f64aac57050a00c0f41fbd0ef2a5d0ad3 (patch)
tree0979bbafa5aeb540a8e64c565074d5aeceb2cff1
parent4b984fe0810a7f46fc01639f12feccdaacf6cc86 (diff)
Fix bug chaining magic methods
-rw-r--r--zend/objectimpl.h50
-rw-r--r--zend/value.cpp2
2 files changed, 26 insertions, 26 deletions
diff --git a/zend/objectimpl.h b/zend/objectimpl.h
index 4d20f3c..110491b 100644
--- a/zend/objectimpl.h
+++ b/zend/objectimpl.h
@@ -32,16 +32,16 @@ private:
* @var zend_object
*/
zend_object php;
-
+
/**
* Pointer to ourselves
* @var ObjectImpl
*/
ObjectImpl *self;
-
-
+
+
} *_mixed;
-
+
/**
* Pointer to the C++ implementation
* @var Base
@@ -69,22 +69,22 @@ public:
{
// allocate a mixed object (for some reason this does not have to be deallocated)
_mixed = (MixedObject *)emalloc(sizeof(MixedObject));
-
+
// copy properties to the mixed object
_mixed->php.ce = entry;
_mixed->self = this;
-
+
// store the c++ object
_object = base;
-
+
// initialize the object
zend_object_std_init(&_mixed->php, entry TSRMLS_CC);
-
+
#if PHP_VERSION_ID < 50399
// tmp variable
zval *tmp;
-
+
// initialize the properties, php 5.3 way
zend_hash_copy(_mixed->php.properties, &entry->default_properties, (copy_ctor_func_t) zval_property_ctor, &tmp, sizeof(zval*));
@@ -93,7 +93,7 @@ public:
// version higher than 5.3 have an easier way to initialize
object_properties_init(&_mixed->php, entry);
-#endif
+#endif
#ifdef ZTS
@@ -101,15 +101,15 @@ public:
// an extra parameter holding thread information
using DestructType = void(*)(zend_object*,unsigned int,void***);
using FreeType = void(*)(zend_object*,void***);
-
+
#else
// not in thread mode: no special parameter for the tsrm_ls variable
using DestructType = void(*)(zend_object*, unsigned int);
using FreeType = void(*)(zend_object*);
-
+
#endif
-
+
// store the two destruct methods in temporary vars
DestructType destructMethod = &ClassImpl::destructObject;
FreeType freeMethod = &ClassImpl::freeObject;
@@ -117,10 +117,10 @@ public:
// the destructor and clone handlers are set to NULL. I dont know why, but they do not
// seem to be necessary...
_handle = zend_objects_store_put(php(), (zend_objects_store_dtor_t)destructMethod, (zend_objects_free_object_storage_t)freeMethod, NULL TSRMLS_CC);
-
+
// set the initial refcount (if it is different than one, because one is the default)
if (refcount != 1) EG(objects_store).object_buckets[_handle].bucket.obj.refcount = refcount;
-
+
// the object may remember that we are its implementation object
base->_impl = this;
}
@@ -142,11 +142,11 @@ public:
{
// pass on to the default destructor
zend_objects_free_object_storage(php() TSRMLS_CC);
-
+
// destruct the object
delete this;
}
-
+
/**
* Find the object based on a zval
* @param val Zval object
@@ -157,7 +157,7 @@ public:
{
// retrieve the old object, which we are going to copy
MixedObject *object = (MixedObject *)zend_object_store_get_object(val TSRMLS_CC);
-
+
// done
return object->self;
}
@@ -170,30 +170,30 @@ public:
static ObjectImpl *find(const zend_object *object)
{
// retrieve the old object, which we are going to copy
- const MixedObject *mixed = (MixedObject *)object;
-
+ const MixedObject *mixed = (const MixedObject *)object;
+
// done
return mixed->self;
}
-
+
/**
* Retrieve the base class of the original C++ object
* @return Base
*/
- Base *object()
+ Base *object() const
{
return _object;
}
-
+
/**
* Pointer to the PHP object
* @return zend_object
*/
- zend_object *php()
+ zend_object *php() const
{
return &_mixed->php;
}
-
+
/**
* Retrieve the handle object
* @return int
diff --git a/zend/value.cpp b/zend/value.cpp
index 9fb59f4..7c95c06 100644
--- a/zend/value.cpp
+++ b/zend/value.cpp
@@ -208,7 +208,7 @@ Value::Value(const Base *object)
obj_bucket->bucket.obj.refcount += 1;
// this is copy-pasted from zend_objects.c - and it is necessary too!
- if (!obj_bucket->bucket.obj.handlers) obj_bucket->bucket.obj.handlers = &std_object_handlers;
+ if (!obj_bucket->bucket.obj.handlers) obj_bucket->bucket.obj.handlers = ClassImpl::objectHandlers(impl->php()->ce);
// store the handlers in the zval too (cast is necessary for php 5.3)
Z_OBJ_HT_P(_val) = (zend_object_handlers*)obj_bucket->bucket.obj.handlers;