为什么有些变量是参数而其他变量不是?

MEM*_*MEM 0 php

这可能是什么原因:

public function __construct($host, $port, $timeout = 5){
    $errnum = 0;
    $errstr = ''; 
Run Code Online (Sandbox Code Playgroud)

而不是这个:

public function __construct($host, $port, $errnum = 0, $errstr = '', $timeout = 5){
Run Code Online (Sandbox Code Playgroud)

为什么有些人是params而有些人不是?

非常感谢,MEM

Jus*_*ier 5

函数定义定义函数本身与调用它的代码之间的契约.

如果调用者应指定它的值,则变量应该只是一个参数.否则,如果变量仅由函数内部使用,则无需将其指定为参数.