可捕获的致命错误:类的对象无法转换为字符串

时间:2015-04-14 14:10:04

标签: php string object-to-string

UrunController.php

public function kontrolAction(){
    $kk = new urunler();
    $kk->kodkontrol($this->request->getPost());
    echo $kk;
}

urunler.php

public function kodkontrol(){
        while(1){
            $UrunKodu = chr(rand(65,90)).chr(rand(65,90)).'-'.rand(1,9999);
            $UKKontrol = $this->findFirst("urunBarkod = '{$UrunKodu}'");
            if($UKKontrol > 0){
                continue;
            } else{
                break;
            }
        }

        echo $UrunKodu;
}

1 个答案:

答案 0 :(得分:1)

实际上,我认为一种方法永远不应该echo。更好的方法是return某事。但无论如何,如果你想回显一个对象,你应该看一下__toString()方法。