Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaces tabs in source code with regular spaces, added example for w…
…orking with global variables
- Loading branch information
1 parent
964d627
commit 80c8a16
Showing
30 changed files
with
748 additions
and
481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
<?php | ||
/** | ||
* exception.cpp | ||
* exception.cpp | ||
* | ||
* @author Jasper van Eck <jasper.vaneck@copernica.com> | ||
* @author Jasper van Eck <jasper.vaneck@copernica.com> | ||
* | ||
* This example shows the working of a C++ function that throws an | ||
* exception, and that exception is then caught by PHP code. | ||
* | ||
* This example shows the working of a C++ function that throws an | ||
* exception, and that exception is then caught by PHP code. | ||
* | ||
*/ | ||
|
||
// try-catch block to be able to handle the exception | ||
try | ||
{ | ||
// the my_throw_exception function is implemented in C++. and | ||
// it is going to throw an exception | ||
my_throw_exception_function(); | ||
// the my_throw_exception function is implemented in C++. and | ||
// it is going to throw an exception | ||
my_throw_exception_function(); | ||
} | ||
catch (Exception $exception) | ||
{ | ||
// the exception object is thrown by C++ code, and caught by PHP | ||
// code | ||
echo $exception->getMessage(). "\n"; | ||
// the exception object is thrown by C++ code, and caught by PHP | ||
// code | ||
echo $exception->getMessage(). "\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.