summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-03 18:03:39 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-03 18:03:39 +0100
commit70986b4bcdf7793c4bb8a4e14d91e6531c95f651 (patch)
tree3009209b9fbcb3d51bc117061a766341c8a71a24 /src
parent8f24af4c28e74ef1769aef6ab00c480e09be7453 (diff)
work in progress for support for creating object instances
Diffstat (limited to 'src')
-rw-r--r--src/classbase.cpp2
-rw-r--r--src/includes.h1
-rw-r--r--src/object.cpp52
-rw-r--r--src/value.cpp12
4 files changed, 60 insertions, 7 deletions
diff --git a/src/classbase.cpp b/src/classbase.cpp
index c7ade6c..af707c4 100644
--- a/src/classbase.cpp
+++ b/src/classbase.cpp
@@ -57,7 +57,7 @@ static zend_object_value create_object(zend_class_entry *type TSRMLS_DC)
// allocate memory for the object
MixedObject *object = (MixedObject *)emalloc(sizeof(MixedObject));
- // find base object
+ // find base object (because the class may have been extended in user space)
zend_class_entry *base = type;
while (base->parent) base = base->parent;
diff --git a/src/includes.h b/src/includes.h
index 59ee8b3..072fab2 100644
--- a/src/includes.h
+++ b/src/includes.h
@@ -47,6 +47,7 @@
#include "../include/type.h"
#include "../include/value.h"
#include "../include/forcedvalue.h"
+#include "../include/object.h"
#include "../include/hiddenpointer.h"
#include "../include/globals.h"
#include "../include/argument.h"
diff --git a/src/object.cpp b/src/object.cpp
new file mode 100644
index 0000000..99de4a0
--- /dev/null
+++ b/src/object.cpp
@@ -0,0 +1,52 @@
+/**
+ * Object.cpp
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2014 Copernica BV
+ */
+#include "includes.h"
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Constructor
+ * @param name
+ */
+Object::Object(const char *name)
+{
+ // step 1: convert the name into a class_entry
+ auto *entry = zend_fetch_class(name, strlen(name), 0);
+ if (!entry) throw Php::Exception("Unknown class name");
+
+ // initiate the zval (which was already allocated in the base constructor)
+ object_init_ex(_val, entry);
+
+// // is there a special function to create the object?
+// if (entry->create_object)
+// {
+// // create the object
+// zend_object_value value = entry->create_object(entry);
+//
+// // wrap this in the zval (which was already allocated in the base constructor)
+// Z_TYPE_P(_val) = IS_OBJECT;
+// Z_OBJVAL_P(_val) = value;
+// }
+// else
+// {
+// }
+
+ // @todo should we call methods like allocating hashtables, copyint and
+ // initializing properties, et cetera?????
+
+ // call the constructor
+ call("__construct");
+}
+
+/**
+ * End namespace
+ */
+}
+
diff --git a/src/value.cpp b/src/value.cpp
index f7eff56..ab4c350 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -1397,8 +1397,8 @@ bool Value::contains(const char *key, int size) const
// retrieve the class entry
auto *entry = zend_get_class_entry(_val);
- // read the property
- zval *property = zend_read_property(entry, _val, key, size, 0);
+ // read the property (cast necessary for php 5.3)
+ zval *property = zend_read_property(entry, _val, (char *)key, size, 0);
// check if valid
return property != nullptr;
@@ -1461,8 +1461,8 @@ Value Value::get(const char *key, int size) const
// retrieve the class entry
auto *entry = zend_get_class_entry(_val);
- // read the property
- zval *property = zend_read_property(entry, _val, key, size, 1);
+ // read the property (case necessary for php 5.3)
+ zval *property = zend_read_property(entry, _val, (char *)key, size, 1);
// wrap in value
return Value(property);
@@ -1534,8 +1534,8 @@ const Value &Value::set(const char *key, int size, const Value &value)
// retrieve the class entry
auto *entry = zend_get_class_entry(_val);
- // update the property
- zend_update_property(entry, _val, key, size, value._val);
+ // update the property (cast necessary for php 5.3)
+ zend_update_property(entry, _val, (char *)key, size, value._val);
}
else
{