Catchable fatal error: Object of class could not be converted to string in

631 Views Asked by At

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

There are 1 best solutions below

0
Edwin Dayot On

Actually, I think a method should never echo anything. The better way is to return something. But anyway, if you want to echo an object, you should take a look at the __toString() method.