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?
Reply to discussion (solution)
function Start (PDO $pdo) {
Formal parameter $pdo
Type declaration PDO
That is, the start method must pass in an object based on the PDO class
If you do not add a type declaration (traditional practice is not added) you may need to check whether the incoming parameters are appropriate
But when added, the PHP parser will help you check that the parameter type is correct.
function Start (PDO $pdo) {
Formal parameter $pdo
Type declaration PDO
That is, the start method must pass in an object based on the PDO class
If you do not add a type declaration (traditional practice is not added) you may need to check whether the incoming parameters are appropriate
But when added, the PHP parser will help you check that the parameter type is correct.
Suddenly understand, if it is a formal parameter to be separated by commas, and this code does not, feel the moderator said the rational. But I'm still a little dizzy, this is not a lot of PHP tutorial, I check the manual.
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 ($number)
{
$number = $number +1;
Echo $number. "
";
}
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.