【发布时间】:2014-10-17 20:41:23
【问题描述】:
它说“可捕获的致命错误:方法 metin_fonk::__toString() 必须返回一个字符串值......”问题出在 uzunluk 方法中的 if 构造上。我认为问题出在 strlen 函数上。这是代码:
class metin_fonk{
public $deger;
public function __construct() {
return $this;
}
public function _($a){
$this->deger = $a;
return $this;
}
public function uzunluk($a,$b){
//$this->deger = (strlen(@$this->deger)>=$a && strlen(@$this->deger)<=$b)? "1" : "0" ;
if(strlen($this->deger)>=$a && strlen($this->deger)<=$b){ //HERE//
$this->deger = "1";
}else{
$this->deger = "0";
}
return $this;
}
public function sql_kac(){
//global $vt;
//$this->deger=$vt->real_escape_string($this->deger);
return $this;
}
public function kirp(){
$this->deger=trim($this->deger);
return $this;
}
public function html_kac(){
$this->deger=htmlspecialchars($this->deger);
return $this;
}
public function __toString(){
return $this->deger;
}
}
$m=new metin_fonk();
$yonetici = $m->_(@$_POST["yonetici"])->sql_kac()->html_kac()->kirp();
if(!empty($yonetici)){
$a = 0;
$b="<div style=\"opacity: 0\">+???+<p>";
$c="</p><br>-???-</div>";
//if (is_string(uzunluk($yonetici,"Adınız",2,30))) {echo $b. uzunluk($yonetici,"Adınız",2,30).$c;$a=1;}
if (!($m->_($yonetici)->uzunluk(2,25))) {echo $b."Adınız en az 2, en fazla 25 karakter uzunluğunda olabilir.".$c;$a=1;}
}
【问题讨论】:
-
“kirp()”函数在哪里?我认为那会是个问题
-
我正在删除无用的部分,看来我也意外删除了它。 kirp() 在实际代码中我正在修复它抱歉。
-
在
kirp()函数中,您应该返回$this->deger而不仅仅是$this。而且你不需要在所有函数中返回$this。 -
但如果我不返回
$this,我将无法链接它们