From 71055ebdea1e8eec30747a04f36e0c10e750bff5 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Fri, 28 Feb 2014 10:25:01 +0100 Subject: a lot of refactoring, to make it much easier to define classes in an extension --- Examples/CppClassesInPhp/Makefile | 4 ++-- Examples/CppClassesInPhp/cppclassinphp.cpp | 23 +++++++++++++++++------ Examples/CppClassesInPhp/cppclassinphp.php | 3 +++ 3 files changed, 22 insertions(+), 8 deletions(-) (limited to 'Examples') diff --git a/Examples/CppClassesInPhp/Makefile b/Examples/CppClassesInPhp/Makefile index 76f0bb1..872cce3 100644 --- a/Examples/CppClassesInPhp/Makefile +++ b/Examples/CppClassesInPhp/Makefile @@ -1,10 +1,10 @@ CPP = g++ RM = rm -f -CPP_FLAGS = -Wall -c -I. -O2 -std=c++11 +CPP_FLAGS = -Wall -c -I. -g -std=c++11 PREFIX = /usr #Edit these lines to correspond with your own directories -LIBRARY_DIR = ${PREFIX}/lib/php5/20121212 +LIBRARY_DIR = ${PREFIX}/lib/php5/20090626 PHP_CONFIG_DIR = /etc/php5/cli/conf.d LD = g++ diff --git a/Examples/CppClassesInPhp/cppclassinphp.cpp b/Examples/CppClassesInPhp/cppclassinphp.cpp index a0871fc..1b567e1 100644 --- a/Examples/CppClassesInPhp/cppclassinphp.cpp +++ b/Examples/CppClassesInPhp/cppclassinphp.cpp @@ -48,6 +48,11 @@ public: } }; +void myFunction(Php::Parameters ¶ms) +{ + std::cout << "regular function" << std::endl; +} + // Symbols are exported according to the "C" language extern "C" @@ -58,12 +63,18 @@ extern "C" // create extension static Php::Extension extension("Cpp_classes_in_php","1.0"); - // add the custom class ot the extension - extension.add("MyClass", Php::Class({ - Php::Public("myMethod", Php::Method(&MyCustomClass::myMethod),{ - Php::ByVal("newX", Php::numericType) - }) - })); + // add custom function + extension.add("myFunction", myFunction, { }); + + // we are going to define a class + Php::Class customClass("MyClass"); + + // add methods to it + // @todo support setting parameter properties + customClass.add("myMethod", &MyCustomClass::myMethod, {}); + + // add the class to the extension + extension.add(customClass); // return the extension module return extension.module(); diff --git a/Examples/CppClassesInPhp/cppclassinphp.php b/Examples/CppClassesInPhp/cppclassinphp.php index 1eccf95..1256018 100644 --- a/Examples/CppClassesInPhp/cppclassinphp.php +++ b/Examples/CppClassesInPhp/cppclassinphp.php @@ -5,6 +5,9 @@ * * An example file to show the working of using a C++ class in PHP. */ + +// run the regular function +myFunction(); //create a MyCustomClass object, which is an object of a C++ class $MyCustomClass = new MyClass(); -- cgit v1.2.3