How to understand the parameters in a custom function? below is a piece of code in a class: static & nbsp; function & nbsp; start (PDO & nbsp; $ pdo) {self :: init ($ pdo); session_set_save_handler (array (_ CLASS __, open), array (_ CLASS __, close user-defined functions)
Below 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 used as the form parameter, which is confusing because I understand that the function is used to pass the parameter and return the result of the passed value. how can this string be passed?
Share: More
------ Solution --------------------
There are three types of parameters: value transfer, reference transfer, and default parameter transfer.
(1) value transfer
Function sum ($ a, $ B)
{
Echo $ a + $ B;
}
Sum (); // start to call this function
?>
(2) transfer a reference
$ MyNum = 100;
Function Valuechange ($ number)
{
$ Number = $ number + 1;
Echo $ number ."
";
}
Valuechange (& $ myNum );
Echo $ myNum;
?>
Result: 101,101
(3) passing default parameters
Function holobby ($ style = "sports ")
{
Return "I like $ style
";
}
Echo holobby ();
Echo holobby ("singing ");
?>
Result: I like sports.
I like singing.