diff options
Diffstat (limited to 'Examples/FunctionNoParameters')
-rw-r--r-- | Examples/FunctionNoParameters/30-phpcpp.ini | 4 | ||||
-rw-r--r-- | Examples/FunctionNoParameters/Makefile | 32 | ||||
-rw-r--r-- | Examples/FunctionNoParameters/functionnoparameters.cpp | 43 | ||||
-rw-r--r-- | Examples/FunctionNoParameters/functionnoparameters.php | 13 |
4 files changed, 92 insertions, 0 deletions
diff --git a/Examples/FunctionNoParameters/30-phpcpp.ini b/Examples/FunctionNoParameters/30-phpcpp.ini new file mode 100644 index 0000000..81d2b5a --- /dev/null +++ b/Examples/FunctionNoParameters/30-phpcpp.ini @@ -0,0 +1,4 @@ +; configuration for php PDO module +; priority=30 +extension=functionnoparameters.so + diff --git a/Examples/FunctionNoParameters/Makefile b/Examples/FunctionNoParameters/Makefile new file mode 100644 index 0000000..6e3ecea --- /dev/null +++ b/Examples/FunctionNoParameters/Makefile @@ -0,0 +1,32 @@ +CPP = g++ +RM = rm -f +CPP_FLAGS = -Wall -c -I. -O2 -std=c++11 + +PREFIX = /usr +#Edit these lines to correspond with your own directories +LIBRARY_DIR = ${PREFIX}/lib/php5/20121212 +PHP_CONFIG_DIR = /etc/php5/cli/conf.d + +LD = g++ +LD_FLAGS = -Wall -shared -O2 +RESULT = functionnoparameters.so + +PHPINIFILE = 30-phpcpp.ini + +SOURCES = $(wildcard *.cpp) +OBJECTS = $(SOURCES:%.cpp=%.o) + +all: ${OBJECTS} ${RESULT} + +${RESULT}: ${OBJECTS} + ${LD} ${LD_FLAGS} -o $@ ${OBJECTS} -lphpcpp + +clean: + ${RM} *.obj *~* ${OBJECTS} ${RESULT} + +${OBJECTS}: + ${CPP} ${CPP_FLAGS} -fpic -o $@ ${@:%.o=%.cpp} + +install: + cp -f ${RESULT} ${LIBRARY_DIR} + cp -f ${PHPINIFILE} ${PHP_CONFIG_DIR} diff --git a/Examples/FunctionNoParameters/functionnoparameters.cpp b/Examples/FunctionNoParameters/functionnoparameters.cpp new file mode 100644 index 0000000..2908ca5 --- /dev/null +++ b/Examples/FunctionNoParameters/functionnoparameters.cpp @@ -0,0 +1,43 @@ +/** + * functionnoparameters.cpp + * @Author Jasper van Eck + * + * An example file to show the working of a function call without parameters. + */ + +/** + * Libraries used. + */ +#include <phpcpp.h> + +/** + * Namespace to use + */ +using namespace std; + +/** + * my_no_parameters_function() + * @return Php::Value + */ +Php::Value my_no_parameters_function() +{ + return "42"; +} + + +// Symbols are exported according to the "C" language +extern "C" +{ + // export the "get_module" function that will be called by the Zend engine + PHPCPP_EXPORT void *get_module() + { + // create extension + static Php::Extension extension("my_function_return_value","1.0"); + + // add function to extension + extension.add("my_no_parameters_function", my_no_parameters_function); + + // return the extension module + return extension.module(); + } +} diff --git a/Examples/FunctionNoParameters/functionnoparameters.php b/Examples/FunctionNoParameters/functionnoparameters.php new file mode 100644 index 0000000..0d07b67 --- /dev/null +++ b/Examples/FunctionNoParameters/functionnoparameters.php @@ -0,0 +1,13 @@ +<?php +/* + * functionnoparameters.php + * @Author Jasper van Eck + * + * An example file to show the working of a function call without parameters. + */ + +/* + * Run a function without parameters. + */ +echo "A function which takes no parameters; my_no_parameters_function()\n"; +echo my_no_parameters_function() . "\n"; |