How to understand the parameters in a user-defined function? 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?
Reply to discussion (solution)
Function start (PDO $ pdo ){
Parameter $ pdo
Type declaration PDO
That is, the start method must pass in an object based on the PDO class.
If the type declaration is not added, you may need to check whether the input parameter is suitable.
However, the php parser will help you check whether the parameter type is correct.
Function start (PDO $ pdo ){
Parameter $ pdo
Type declaration PDO
That is, the start method must pass in an object based on the PDO class.
If the type declaration is not added, you may need to check whether the input parameter is suitable.
However, the php parser will help you check whether the parameter type is correct.
I suddenly understood that if it is a form parameter that should be separated by commas, and this code does not, I feel that the moderator is right. However, I am still a little dizzy. I haven't found this method in many php tutorials. I will check the manual.
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.