summaryrefslogtreecommitdiff
path: root/Examples/FunctionWithParameters/functionwithparameters.php
blob: 0ca360e0b94c02f922542dc867820b85ee6fcb91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
 *	functionwithparameters.php
 * 	@author Jasper van Eck<jasper.vaneck@copernica.com>
 * 
 * 	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. 
 */
 

/* 
 * 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 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.
 */