summaryrefslogtreecommitdiff
path: root/Examples/ReturnObject/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Examples/ReturnObject/main.cpp')
-rw-r--r--Examples/ReturnObject/main.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/Examples/ReturnObject/main.cpp b/Examples/ReturnObject/main.cpp
new file mode 100644
index 0000000..6ad3552
--- /dev/null
+++ b/Examples/ReturnObject/main.cpp
@@ -0,0 +1,37 @@
+#include <phpcpp.h>
+#include "master.h"
+#include "child.h"
+
+/**
+ * tell the compiler that the get_module is a pure C function
+ */
+extern "C" {
+
+ /**
+ * Function that is called by PHP right after the PHP process
+ * has started, and that returns an address of an internal PHP
+ * strucure with all the details and features of your extension
+ *
+ * @return void* a pointer to an address that is understood by PHP
+ */
+ PHPCPP_EXPORT void *get_module()
+ {
+ // static(!) Php::Extension object that should stay in memory
+ // for the entire duration of the process (that's why it's static)
+ static Php::Extension extension("returnobjecy", "1.0");
+
+ // we have to class - master and child
+ Php::Class<Master> master("master");
+ Php::Class<Child> child("child");
+
+ // the master class has one method - to return a child
+ master.method("child", &Master::child);
+
+ // add all classes to the extension
+ extension.add(master);
+ extension.add(child);
+
+ // return the extension
+ return extension;
+ }
+}