summaryrefslogtreecommitdiff
path: root/Examples
diff options
context:
space:
mode:
authorJasperVanEck <jaspergkurtz@gmail.com>2013-12-02 12:28:32 +0100
committerJasperVanEck <jaspergkurtz@gmail.com>2013-12-02 12:28:32 +0100
commit040f493080df2787557b891713d5f851ac78cae6 (patch)
tree00a848964c7191a18fa3d1af4042866c1edf18e7 /Examples
parentc97224558d022b5698fb000018f910f2499df1b4 (diff)
isCallable now works
Diffstat (limited to 'Examples')
-rw-r--r--Examples/CallPhpFunctions/callphpfunction.cpp9
-rw-r--r--Examples/CallPhpFunctions/callphpfunction.php12
2 files changed, 13 insertions, 8 deletions
diff --git a/Examples/CallPhpFunctions/callphpfunction.cpp b/Examples/CallPhpFunctions/callphpfunction.cpp
index db443ea..8f212f8 100644
--- a/Examples/CallPhpFunctions/callphpfunction.cpp
+++ b/Examples/CallPhpFunctions/callphpfunction.cpp
@@ -24,8 +24,10 @@ using namespace std;
*/
Php::Value call_php_function(Php::Parameters &params)
{
- //if (!params[0].isCallable()) throw Php::Exception("Not a callable type.");
-
+ // 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);
}
@@ -41,7 +43,8 @@ extern "C"
// add function to extension
extension.add("call_php_function", call_php_function, {
- Php::ByVal("addFunc", Php::callableType)
+ Php::ByVal("addFunc", Php::callableType),
+ Php::ByVal("x", Php::numericType)
});
// return the extension module
diff --git a/Examples/CallPhpFunctions/callphpfunction.php b/Examples/CallPhpFunctions/callphpfunction.php
index 26f161c..ae3cf81 100644
--- a/Examples/CallPhpFunctions/callphpfunction.php
+++ b/Examples/CallPhpFunctions/callphpfunction.php
@@ -6,11 +6,13 @@
* An example file to show the working of a php function call in C++.
*/
-/*
- * Run the function with the given name. As you can see, the given name
- * can be different from the actual function name.
+/**
+ * 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){
- return $a + $b + $c;
+ return $a + $b + $c;
});
-echo $result;
+// print the result
+echo $result . "\n";