xiaosier / libweibo

新浪微博开放平台php sdk(Sina Weibo open platform php sdk)
http://open.weibo.com
394 stars 185 forks source link

调整 saetv2.ex.class.php 类 function getAccessToken 方法(函数)默认参数的不正确用法 #24

Open Tinywan opened 6 years ago

Tinywan commented 6 years ago

函数默认参数的不正确用法

function getAccessToken($type = 'code',$keys)
{
    return "Making a bowl of $type $keys.\n";
}
echo getAccessToken("raspberry");   // won't work as expected

以上例程会输出

Warning: Missing argument 2 in call to makeyogurt() in 
/usr/local/etc/httpd/htdocs/phptest/functest.html on line 41
Making a bowl of raspberry .

函数默认参数正确的用法

function getAccessToken($keys,$type = 'code' )
{
return "Making a bowl of $type $keys.\n";
}
echo getAccessToken("raspberry");   // works as expected

PHP官方文档

Tinywan commented 6 years ago

?