summaryrefslogtreecommitdiff
path: root/Examples
diff options
context:
space:
mode:
authorJasperVanEck <jaspergkurtz@gmail.com>2013-12-02 14:08:45 +0100
committerJasperVanEck <jaspergkurtz@gmail.com>2013-12-02 14:08:45 +0100
commit2f6a58cb1bcb4250652b54416ccf80946adb0c34 (patch)
tree49eb0ea7914cf5dad39ee16c569afe92ce37b1ca /Examples
parent040f493080df2787557b891713d5f851ac78cae6 (diff)
Updated README.md, implemented more complicated isCallable method and added comments to value.cpp
Diffstat (limited to 'Examples')
-rw-r--r--Examples/CallPhpFunctions/callphpfunction.php23
-rw-r--r--Examples/README.md15
2 files changed, 33 insertions, 5 deletions
diff --git a/Examples/CallPhpFunctions/callphpfunction.php b/Examples/CallPhpFunctions/callphpfunction.php
index ae3cf81..77d633c 100644
--- a/Examples/CallPhpFunctions/callphpfunction.php
+++ b/Examples/CallPhpFunctions/callphpfunction.php
@@ -6,13 +6,28 @@
* 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 myFunction($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.
*/
-$result = call_php_function(function($a, $b, $c){
+echo(call_php_function(function($a, $b, $c){
return $a + $b + $c;
- });
-// print the result
-echo $result . "\n";
+ })."\n");
+
+echo(call_php_function("myFunction")."\n");
+
+echo(call_php_function(array(new MyClass(), 'method'))."\n");
diff --git a/Examples/README.md b/Examples/README.md
index ac66425..5bd9e1e 100644
--- a/Examples/README.md
+++ b/Examples/README.md
@@ -126,10 +126,23 @@ The following examples are available:
implemented. It would need to be implemented for this specific
example to work.
- Functions and/or classes defined in this Example.
+ Functions and/or classes defined in this example.
- void my_catch_exception_function(Php::Parameters &params)
- void my_throw_exception_function()
+### [PHP function calls](https://github.com/EmielBruijntjes/PHP-CPP/tree/master/Examples/CallPhpFunctions)
+
+ The seventh example shows how to pass a callable PHP function as
+ a parameter. As can be seen in the example, there are several ways
+ of passing a PHP function to the C++ function. When a function is
+ passed, it is possible to use the () operator on the parameter, with
+ the correct amount of parameters for the callable PHP function.
+ When using the wrong amount, or when trying to use the () operator
+ on a non-callable type, you will get PHP errors rather than
+ segmentation faults or other kinds of C++ errors.
+
+ Functions and/or classes defined in this example.
+ - Php::Value call_php_function(Php::Parameters &params)