變量已經在方法中定義但執行的時候還報錯?
Notice: Undefined variable: link_start in D:\wamp\www\mysqli\comment.class.php on line?70這個變量已經定義在這個方法里面了,但是那個首頁還是報錯?
這下面是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='發布于{$dateStr}'>
?? ??? ??? ??? ?{$dateStr}
?? ??? ??? ?</div>
?? ??? ??? ?<p>{$this->data['content']}</p>
?? ??? ?</div>
EOF;
?? ??? ??? ?return $res;
?? ?}
70行的代碼是<div class='face'>下的{link_start}這里,其他地方的link_start, link_end 也報錯,請問這是什么 原因?
2015-07-04
直接修改PHP配置文件中error_reporting=E_ALL&~E_NOTICE,重啟服務器即可
^-^...
2016-11-01
回復 早安EchoMichael:我今天剛遇到這個問題,困擾了我兩天,至于這個問題出現的原因,我猜測是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='發布于{$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='發布于{$dateStr}'>
? ? ? ? ? ? ? ? {$dateStr}
? ? ? ? ? ? </div>
? ? ? ? ? ? <p>{$this->data['content']}</p>
? ? ? ? </div>
EOF;
? ? ? ? ? ? return $res;
? ? ? ? }
對當前url地址做一個判斷,如果存在則傳入地址,否則不使用超連接,測試了一下,效果是一樣的
希望這對你有幫助 互相幫助 共同進步
2016-06-30
根本不是erro_reporting的問題,是因為$this->data['url']為空時沒有任何處理