[英]PHP error, if-statement
什么擰這個代碼?
if(isset($this->session->flashdata('login_error'))) { // Line 39
echo "You entered an incorrect email or password!";
}
我使用Codeigniter並在autoload.php
中autoload.php
會話。
我得到的錯誤信息是:
致命錯誤:無法在第39行的/Applications/XAMPP/xamppfiles/htdocs/application/views/login_view.php中的寫入上下文中使用方法返回值
只有在嘗試使用可能不存在的變量時才需要isset
。 在你的情況下,你正在調用一個肯定存在的函數 。 因此你不需要,實際上不能在這里使用isset
。 如果你想測試值是否真實,只需使用if ($this->session->flashdata('login_error'))
。
只檢查if($ this-> session-> flashdata('login_error'))是否會返回false,如果此函數的結果是布爾值FALSE或NULL
你不能使用像這樣的isset
函數。 你能做的是:
$txt = $this->session->flashdata('login_error');
if(!empty($txt))
{
echo "You entered an incorrect email or password!";
}
isset
僅檢查實例化的變量。 由於您只能返回實例化變量,因此isset
無效。 你最好的選擇就是這樣做:
if($this->session->flashdata('login_error') != null) { // Line 39
echo "You entered an incorrect email or password!";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.