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 --- .../functionwithparameters.php | 70 +++++++++++++++++++--- 1 file changed, 62 insertions(+), 8 deletions(-) (limited to 'Examples/FunctionWithParameters/functionwithparameters.php') diff --git a/Examples/FunctionWithParameters/functionwithparameters.php b/Examples/FunctionWithParameters/functionwithparameters.php index b1eff25..0ca360e 100644 --- a/Examples/FunctionWithParameters/functionwithparameters.php +++ b/Examples/FunctionWithParameters/functionwithparameters.php @@ -6,16 +6,70 @@ * 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()"; + } + + public function getMemberVar() + { + return $aMemberVar; + } +} + /* * Run a function with parameters. */ -echo 'A function which takes parameters, which are all undefined;' . - '\nmy_with_undefined_parameters_function("1st","2nd","3rd","4th")\n'; -echo my_with_undefined_parameters_function("1st","2nd","3rd","4th") . '\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'; +/* + * A function which takes parameters, which are all undefined; + * my_with_undefined_parameters_function('1st','2nd','3rd','4th') + */ +echo my_with_undefined_parameters_function('1st','2nd','3rd','4th') . "\n\n\n"; + +/* + * A function which takes parameters, which are all defined; + * my_with_defined_parameters_function(21,42) + */ + +echo my_with_defined_parameters_function(21,42) . "\n\n\n"; + +/* + * A function which takes a reference of a parameter + * my_with_defined_parameters_reference_function(referenceVar) + */ + +$referenceVar = "I am unchanged."; +echo "The value of referenceVar: " . $referenceVar. "\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'; +echo my_with_defined_parameters_reference_function($referenceVar) . "\n"; + +echo "New value of referenceVar: " . $referenceVar ."\n\n\n"; + +/* + * A function which takes an array as a parameter + * my_with_defined_array_parameters_function($myArray) + */ +$myArray = array("a", "b", "c", "d"); +echo my_with_defined_array_parameters_function($myArray) . "\n\n\n"; + +/* + * A function which takes an object as a parameter + * my_with_defined_object_parameter_function(myPhpClass) + */ + +$myPhpClass = new MyPhpClass; +echo my_with_defined_object_parameters_function($myPhpClass); + +/* + * Accessing a non-existant parameters index will result in a segmentation fault. + * The segmentation fault will also occur when passing the wrong type of parameter. + */ -- cgit v1.2.3