From 80c8a16fb145f7ed4867d31fad3c22318a1ce708 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sat, 7 Dec 2013 13:12:25 -0800 Subject: replaces tabs in source code with regular spaces, added example for working with global variables --- Examples/Globals/globals.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Examples/Globals/globals.cpp (limited to 'Examples/Globals/globals.cpp') diff --git a/Examples/Globals/globals.cpp b/Examples/Globals/globals.cpp new file mode 100644 index 0000000..6fa9eea --- /dev/null +++ b/Examples/Globals/globals.cpp @@ -0,0 +1,60 @@ +/** + * functionvoid.cpp + * @author Emiel Bruijntjes + * + * An example file to show how global variables can be accessed + */ + +/** + * Libraries used. + */ +#include +#include + +/** + * Namespace to use + */ +using namespace std; + +/** + * process_globals() + * + * This function reads and modifies global variables + */ +Php::Value process_globals() +{ + // all global variables can be accessed via the Php::globals variable, + // which is more or less the same as the PHP $_GLOBALS variable + + // set a global variable + Php::globals["a"] = 1; + + // increment a global variable + Php::globals["b"] += 1; + + // set a global variable to be an array + Php::globals["c"] = Php::Array(); + + // add a member to an array + Php::globals["c"]["member"] = 123; + + // if a global variable holds a function, we can call it + return Php::globals["d"](1,2,3); +} + +// 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("globals","1.0"); + + // add function to extension + extension.add("process_globals", process_globals); + + // return the extension module + return extension.module(); + } +} -- cgit v1.2.3