0

アプリに次のコンポーネントがあります。

class ImageComponent extends Component {


var $image;
var $image_type;

function __construct($filename = null){
    if(!empty($filename)){
        $this->load($filename);
    }
}

function load($filename) {
    $image_info = getimagesize($filename); //<<== LINE OF THE ERROR
    $this->image_type = $image_info[2];
    if( $this->image_type == IMAGETYPE_JPEG ) {
        $this->image = imagecreatefromjpeg($filename);
    } elseif( $this->image_type == IMAGETYPE_GIF ) {
        $this->image = imagecreatefromgif($filename);
    } elseif( $this->image_type == IMAGETYPE_PNG ) {
        $this->image = imagecreatefrompng($filename);
    } else {
        throw new Exception("The file you're trying to open is not supported");
    }

}
}

しかし、コンポーネントをロードすると、次のエラーが表示されます。

 getimagesize() expects parameter 1 to be string, object given [APP/Controller/Component/ImageComponent.php, line 33]

ありがとう

4

1 に答える 1

0

コンポーネントのコンストラクターは、最初のパラメーターが ComponentCollection オブジェクトであることを想定しています。余談ですが、親のクラス関数のパラメーター型を変更するのはコードの匂いです

于 2013-10-20T20:43:16.403 に答える