From 9185842b1d2fd352f6d71a46d2017fa25cc3c6a7 Mon Sep 17 00:00:00 2001 From: JasperVanEck Date: Thu, 28 Nov 2013 15:46:02 +0100 Subject: Additional functions with parameters; references, objects and arrays --- .../CppClassesInPhp/functionwithparameters.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Examples/CppClassesInPhp/functionwithparameters.php (limited to 'Examples/CppClassesInPhp/functionwithparameters.php') diff --git a/Examples/CppClassesInPhp/functionwithparameters.php b/Examples/CppClassesInPhp/functionwithparameters.php new file mode 100644 index 0000000..3b241d0 --- /dev/null +++ b/Examples/CppClassesInPhp/functionwithparameters.php @@ -0,0 +1,49 @@ + + * + * An example file to show the working of a function call with parameters, defined and undefined. + */ + +/* + * Test class. + */ +class MyPhpClass { + + public $aMemberVar = "aMemberVar"; + + public function __toString() + { + return "MyPhpClass.__toString()"; + } +} + +/* + * Run a function with parameters. + */ +echo "A function which takes parameters, which are all undefined;" . + "\n my_with_undefined_parameters_function('1st','2nd','3rd','4th')\n"; +echo my_with_undefined_parameters_function('1st','2nd','3rd','4th') . "\n\n\n"; + +echo "A function which takes parameters, which are all defined; " . + "\nmy_with_defined_parameters_function(21,42)\n"; +echo my_with_defined_parameters_function(21,42) . "\n\n\n"; + +echo "A function which takes a reference of a parameter;" . + "\nmy_with_defined_parameters_reference_function(referenceVar)\n"; + +$referenceVar = "I am unchanged."; +echo "The value of referenceVar: " . $referenceVar. "\n"; + +echo my_with_defined_parameters_reference_function($referenceVar) . "\n"; + +echo "New value of referenceVar: " . $referenceVar ."\n\n\n"; + +$myPhpClass = new MyPhpClass; +echo "A function which takes an object as a parameter;" . + "\nmy_with_defined_object_parameter_function(myPhpClass)"; +echo my_with_defined_object_parameters_function($myPhpClass) . "\n\n\n"; + +echo "Accessing a non-existant parameters index will result in a segmentation fault.\n"; +echo "The segmentation fault will also occur when passing the wrong type of parameter.\n"; -- cgit v1.2.3