具有重复名称的函数参数

时间:2018-02-28 12:40:04

标签: php function php-7

我在php 5.6中使用下面的代码并且工作正常,但现在我升级到php7并导致致命错误。

代码:

public function object_all_images($img_type = "thumb", 
$img_type = "jpg")
    {
        $path = "";
        $this->default_image_paths();
        if( $img_type === "thumb" ) 
        {
            $directory = $this->es_thumbDir;
        }
        else
        {
            $directory = $this->es_imgDir;
        }
  

致命错误:重新定义参数

1 个答案:

答案 0 :(得分:2)

你的函数必须像这样才能得到两个参数的值。

public function object_all_images($img_type = "thumb", 
$img_format = "jpg")
{
    $path = "";
    $this->default_image_paths();
    if( $img_type === "thumb" ) 
    {
        $directory = $this->es_thumbDir;
    }
    else
    {
        $directory = $this->es_imgDir;
    }
}