Custom functions How to understand the parameters in this way
The following is a piece of code in a class
static function Start (PDO $pdo) {
Self::init ($PDO);
Session_set_save_handler (
Array (__class__, "open"),
Array (__class__, "close"),
Array (__class__, "read"),
Array (__class__, "write"),
Array (__class__, "destroy"),
Array (__class__, "GC")
);
Session_Start ();
}
The PDO in this function is a parameter, which is confusing because I understand that the function is to pass a parameter and return the result of the returned value, and how does this string pass?
Share to: more
------Solution--------------------
There are three types of formal parameters: value passing, reference passing, and default parameter passing three mechanisms.
(1) Value transfer
function sum ($a, $b)
{
Echo $a + $b;
}
SUM (10,20); Start calling the function
?>
(2) Reference passing
$myNum = 100;
function Valuechange ()
{
= +1;
Echo. "
";
}
Valuechange (
&$myNum);
Echo $myNum;
?>
Results: 101,101
(3) Default parameter passing
function Hobby ($style = "Motion")
{
Return "I like $style
";
}
echo Hobby ();
Echo Hobby ("singing");
?>
Result: I like sports
I like singing.