變量已經(jīng)在方法中定義但執(zhí)行的時(shí)候還報(bào)錯(cuò)?
Notice: Undefined variable: link_start in D:\wamp\www\mysqli\comment.class.php on line?70這個(gè)變量已經(jīng)定義在這個(gè)方法里面了,但是那個(gè)首頁還是報(bào)錯(cuò)?
這下面是comment.class.php中的代碼
public function output(){
?? ??? ?if($this->data['url']){
?? ??? ??? ?$link_start="<a href='".$this->data['url']."' target='_blank'>";
?? ??? ??? ?$link_end="</a>";
?? ??? ?}
?? ??? ?$dateStr=date("Y年m月d日 H:i:s",$this->data['pubTime']);
?? ??? ?$res=<<<EOF
?? ??? ?<div class='comment'>
?? ??? ??? ?<div class='face'>
?? ??? ??? ??? ?{$link_start}
?? ??? ??? ??? ??? ?<img width='50' height='50' src="img/{$this->data['face']}.jpg" alt="" />
?? ??? ??? ??? ?{$link_end}
?? ??? ??? ?</div>
?? ??? ??? ?<div class='username'>
?? ??? ??? ??? ?{$link_start}
?? ??? ??? ??? ?{$this->data['username']}
?? ??? ??? ??? ?{$link_end}
?? ??? ??? ?</div>
?? ??? ??? ?<div class='date' title='發(fā)布于{$dateStr}'>
?? ??? ??? ??? ?{$dateStr}
?? ??? ??? ?</div>
?? ??? ??? ?<p>{$this->data['content']}</p>
?? ??? ?</div>
EOF;
?? ??? ??? ?return $res;
?? ?}
70行的代碼是<div class='face'>下的{link_start}這里,其他地方的link_start, link_end 也報(bào)錯(cuò),請(qǐng)問這是什么 原因?
2015-07-04
直接修改PHP配置文件中error_reporting=E_ALL&~E_NOTICE,重啟服務(wù)器即可
^-^...
2016-11-01
回復(fù) 早安EchoMichael:我今天剛遇到這個(gè)問題,困擾了我兩天,至于這個(gè)問題出現(xiàn)的原因,我猜測(cè)是php版本不同解析代碼不同的問題,
我的解決辦法如下:
if($this->data['url']){
? ? ? ? ? ? $url=$this->data['url'];
? ? ? ? ? ? $dateStr=date("Y年m月d日 H:i:s",$this->data['pubTime']);
? ? ? ? ? ? $res=<<<EOF
? ? ? ? <div class='comment'>
? ? ? ? ? ? <div class='face'>
? ? ? ? ? ? ? ? <a href="{$url}" target='_blank'>
? ? ? ? ? ? ? ? ? ? <img width='50' height='50' src="img/{$this->data['face']}.jpg">
? ? ? ? ? ? ? ? </a>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class='username'>
? ? ? ? ? ? ? ? <a href="{$url}" target='_blank'>
? ? ? ? ? ? ? ? ? ? {$this->data['username']}
? ? ? ? ? ? ? ? </a>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class='date' title='發(fā)布于{$dateStr}'>
? ? ? ? ? ? ? ? {$dateStr}
? ? ? ? ? ? </div>
? ? ? ? ? ? <p>{$this->data['content']}</p>
? ? ? ? </div>
EOF;
? ? ? ? ? ? return $res;
? ? ? ? }else{
? ? ? ? ? ? $dateStr=date("Y年m月d日 H:i:s",$this->data['pubTime']);
? ? ? ? ? ? $res=<<<EOF
? ? ? ? <div class='comment'>
? ? ? ? ? ? <div class='face'>
? ? ? ? ? ? ? ? ? ? <img width='50' height='50' src="img/{$this->data['face']}.jpg">
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class='username'>
? ? ? ? ? ? ? ? ? ? {$this->data['username']}
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class='date' title='發(fā)布于{$dateStr}'>
? ? ? ? ? ? ? ? {$dateStr}
? ? ? ? ? ? </div>
? ? ? ? ? ? <p>{$this->data['content']}</p>
? ? ? ? </div>
EOF;
? ? ? ? ? ? return $res;
? ? ? ? }
對(duì)當(dāng)前url地址做一個(gè)判斷,如果存在則傳入地址,否則不使用超連接,測(cè)試了一下,效果是一樣的
希望這對(duì)你有幫助 互相幫助 共同進(jìn)步
2016-06-30
根本不是erro_reporting的問題,是因?yàn)?this->data['url']為空時(shí)沒有任何處理