How to understand the form parameters such as user-defined functions

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.