From 2e25bc7e1b9faf89e6057ed7874ef2f4a8c86ca1 Mon Sep 17 00:00:00 2001 From: Toon Schoenmakers Date: Fri, 21 Nov 2014 13:51:04 +0100 Subject: Removed move constructor from Object class, because it caused failures when instantiating with a std::string parameter, Php::Object constructors now always first call the base constructor, and the __construct() function is now always called --- include/object.h | 40 +++++++++++++++++----------------------- zend/object.cpp | 20 +++++++------------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/include/object.h b/include/object.h index 124c0b3..29f4110 100644 --- a/include/object.h +++ b/include/object.h @@ -24,16 +24,6 @@ public: */ Object() : Value(Type::Object) {} - /** - * Move constructor is passed to the parent - * @param value - */ - Object(Value &&value) : Value(std::move(value)) - { - // throw exception in case of problems - if (value.type() != Type::Object) throw FatalError("Constructing an object variable by moving a non object"); - } - /** * Copy constructor is valid if the passed in object is also an object, * or when it is a string holding a classname @@ -92,17 +82,17 @@ public: * @param arg8 Optional argument 9 * @param arg9 Optional argument 10 */ - Object(const char *name) { instantiate(name); call("__construct"); } - Object(const char *name, Value p0) { instantiate(name); call("__construct", p0); } - Object(const char *name, Value p0, Value p1) { instantiate(name); call("__construct", p0, p1); } - Object(const char *name, Value p0, Value p1, Value p2) { instantiate(name); call("__construct", p0, p1, p2); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3) { instantiate(name); call("__construct", p0, p1, p2, p3); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4) { instantiate(name); call("__construct", p0, p1, p2, p3, p4); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5, p6); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5, p6, p7); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5, p6, p7, p8); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } + Object(const char *name) : Value(Type::Object) { if (instantiate(name)) call("__construct"); } + Object(const char *name, Value p0) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0); } + Object(const char *name, Value p0, Value p1) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0, p1); } + Object(const char *name, Value p0, Value p1, Value p2) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0, p1, p2); } + Object(const char *name, Value p0, Value p1, Value p2, Value p3) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0, p1, p2, p3); } + Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4); } + Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5); } + Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5, p6); } + Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5, p6, p7); } + Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5, p6, p7, p8); } + Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) : Value(Type::Object) { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } /** * Destructor @@ -165,10 +155,14 @@ public: private: /** * Helper method to instantiate an object + * + * This method returns true if there is a __construct() function, and + * false otherwise + * * @param name Class name - * @return zend_class_entry + * @return bool */ - struct _zend_class_entry *instantiate(const char *name); + bool instantiate(const char *name); }; /** diff --git a/zend/object.cpp b/zend/object.cpp index 30fdcdb..a4eaf1e 100644 --- a/zend/object.cpp +++ b/zend/object.cpp @@ -17,7 +17,7 @@ namespace Php { * @param name Name of the class to instantiate * @param base Implementation of the class */ -Object::Object(const char *name, Base *base) +Object::Object(const char *name, Base *base) : Value(Type::Object) { // does the object already have a handle? if (base->implementation()) @@ -56,20 +56,14 @@ Object::Object(const char *name, Base *base) * or when it is a string holding a classname * @param that An other object */ -Object::Object(const Value &value) : Value() +Object::Object(const Value &value) : Value(Type::Object) { // when a string is passed in, we are going to make a new instance of the // passed in string if (value.isString()) { // instantiate the object - auto *entry = instantiate(value); - - // leap out if there is no __construct function - if (!zend_hash_exists(&entry->function_table, "__construct", 12)) return; - - // call the construct function - call("__construct"); + if (instantiate(value)) call("__construct"); } else { @@ -81,9 +75,9 @@ Object::Object(const Value &value) : Value() /** * Internal method to instantiate an object * @param name Name of the class to instantiate - * @return zend_class_entry + * @return bool True if there is a __construct function */ -zend_class_entry *Object::instantiate(const char *name) +bool Object::instantiate(const char *name) { // we need the tsrm_ls variable TSRMLS_FETCH(); @@ -107,8 +101,8 @@ zend_class_entry *Object::instantiate(const char *name) // @todo is this a memory leak? the base class first initializes a stdClass, // and then we overwrite it with a specific class - // return the class entry - return entry; + // return whether there is a __construct function + return zend_hash_exists(&entry->function_table, "__construct", 12); } /** -- cgit v1.2.3