具有重复名称的函数参数

问题描述 投票:-3回答:1

我在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;
        }

致命错误:重新定义参数

php function php-7
1个回答
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;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.