diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-12-07 13:12:25 -0800 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-12-07 13:12:25 -0800 |
commit | 80c8a16fb145f7ed4867d31fad3c22318a1ce708 (patch) | |
tree | f7605cdb86d653efaac761363ed596dd6b2e0459 /Examples/Globals/globals.cpp | |
parent | 964d6274b0eba38df43d77b87c44bd728d2f0fb5 (diff) |
replaces tabs in source code with regular spaces, added example for working with global variables
Diffstat (limited to 'Examples/Globals/globals.cpp')
-rw-r--r-- | Examples/Globals/globals.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
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 <emiel.bruijntjes@copernica.com> + * + * An example file to show how global variables can be accessed + */ + +/** + * Libraries used. + */ +#include <iostream> +#include <phpcpp.h> + +/** + * 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(); + } +} |