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/CallPhpFunctions | |
parent | 964d6274b0eba38df43d77b87c44bd728d2f0fb5 (diff) |
replaces tabs in source code with regular spaces, added example for working with global variables
Diffstat (limited to 'Examples/CallPhpFunctions')
-rw-r--r-- | Examples/CallPhpFunctions/callphpfunction.cpp | 48 | ||||
-rw-r--r-- | Examples/CallPhpFunctions/callphpfunction.php | 30 |
2 files changed, 39 insertions, 39 deletions
diff --git a/Examples/CallPhpFunctions/callphpfunction.cpp b/Examples/CallPhpFunctions/callphpfunction.cpp index 8f212f8..9932a3e 100644 --- a/Examples/CallPhpFunctions/callphpfunction.cpp +++ b/Examples/CallPhpFunctions/callphpfunction.cpp @@ -1,12 +1,12 @@ /** - * callphpfunction.cpp - * @author Jasper van Eck<jasper.vaneck@copernica.com> + * callphpfunction.cpp + * @author Jasper van Eck<jasper.vaneck@copernica.com> * - * An example file to show the working of a php function call in C++. + * An example file to show the working of a php function call in C++. */ /** - * Libraries used. + * Libraries used. */ #include <iostream> #include <phpcpp.h> @@ -17,37 +17,37 @@ using namespace std; /** - * call_php_function() - * Calls a function in PHP space. - * @param ¶ms - * @return Php::Value + * call_php_function() + * Calls a function in PHP space. + * @param ¶ms + * @return Php::Value */ Php::Value call_php_function(Php::Parameters ¶ms) { - // check whether the parameter is callable - if (!params[0].isCallable()) throw Php::Exception("Not a callable type."); - - // perform the callback - return params[0](1,2,3); + // check whether the parameter is callable + if (!params[0].isCallable()) throw Php::Exception("Not a callable type."); + + // perform the callback + return params[0](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 + // export the "get_module" function that will be called by the Zend engine + PHPCPP_EXPORT void *get_module() + { + // create extension static Php::Extension extension("call_php_function","1.0"); // add function to extension extension.add("call_php_function", call_php_function, { - Php::ByVal("addFunc", Php::callableType), - Php::ByVal("x", Php::numericType) - }); - - // return the extension module - return extension.module(); - } + Php::ByVal("addFunc", Php::callableType), + Php::ByVal("x", Php::numericType) + }); + + // return the extension module + return extension.module(); + } } diff --git a/Examples/CallPhpFunctions/callphpfunction.php b/Examples/CallPhpFunctions/callphpfunction.php index 77d633c..8da284d 100644 --- a/Examples/CallPhpFunctions/callphpfunction.php +++ b/Examples/CallPhpFunctions/callphpfunction.php @@ -1,33 +1,33 @@ <?php /** - * callphpfunction.php - * @author Jasper van Eck<jasper.vaneck@copernica.com> + * callphpfunction.php + * @author Jasper van Eck<jasper.vaneck@copernica.com> * - * An example file to show the working of a php function call in C++. + * An example file to show the working of a php function call in C++. */ class MyClass { - function method($a,$b,$c) - { - return $a+$b+$c; - } + function method($a,$b,$c) + { + return $a+$b+$c; + } } function myFunction($a,$b,$c) { - return $a+$b+$c; + return $a+$b+$c; } /** - * Call a C++ function with a callable PHP function as its parameter. - * The PHP function is then executed from the C++ code. - * The PHP function is this case, adds three numbers. + * Call a C++ function with a callable PHP function as its parameter. + * The PHP function is then executed from the C++ code. + * The PHP function is this case, adds three numbers. */ echo(call_php_function(function($a, $b, $c){ - return $a + $b + $c; - })."\n"); - + return $a + $b + $c; + })."\n"); + echo(call_php_function("myFunction")."\n"); - + echo(call_php_function(array(new MyClass(), 'method'))."\n"); |