Troubleshooting of PHP errors: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
| Line 58: | Line 58: | ||
== troubleshooting steps of function == | == troubleshooting steps of function == | ||
simply the question | simply the question | ||
* | * Is the [http://php.net/manual/en/function.function-exists.php function_exists]? If not, looking for the alternative functions. | ||
* | * Was the function really executed? Maybe using the __LINE__ to examin the logic. | ||
* | * Disable the logical judgement and just print text | ||
* Check the if-else condition was satisfied or not cf: [http://www.leepoint.net/notes-java/data/strings/12stringcomparison.html Java: String Comparison] It's logical (compiler will not show the warning) but wrong. | |||
== references == | == references == | ||
Revision as of 18:43, 4 September 2013
PHP 問題的排除解決
檔案操作有關
- 可否讀取或寫入:例如 imagejpeg($canvas, $filename, 100); 沒有顯示錯誤訊息,則需要
- 檢查暫存目錄是否可以寫入 upload - PHP way to find the web server's temp path? - Stack Overflow
- 檢查該檔案所在該目錄是否已經建立,若未建立則需要建立 mkdir,並設定可以寫入。如果是巢狀的多層目錄,則需要啟用 $recursive [1]
- 檢查該檔案是否可以寫入 is_writable
使用者操作/使用者輸入的內容
使用者輸入內容,內容可能是
- 空值
- 包含特殊符號 ex: 單引號 ', 雙引號 ", > < <== 對策: PHP: htmlentities - Manual
- 包含換行符號
- 內容的前後有空白 <== 對策: PHP: trim 或 jQuery $.trim('string')
- 超出預期的內容長度
- 重複的內容 ex: Excel 欄位重複
- (可勾選多個項目的狀況下) 指勾選了單一項目或者沒有勾選項目,就送出(submit)表格
使用者操作
- 重複點選按鈕
- 在輸入框按 Enter
操作順序
- 使用者的操作順序,可能不按照功能設計的順序
- 沒有選取任何項目,就提交(submit)或操作表格
錯誤訊息
執行PHP時顯示原始碼的錯誤
- 確認伺服器是否能執行 PHP。驗證: phpinfo
- 如果 PHP 使用 short tag語法撰寫,則 php.ini 檔案 需要開啟 short_open_tag = Off -> On
錯誤訊息: ERROR: 00000::
- 原因: 想要刪除的資料不在 MySQL 資料庫內,進行刪除時,會發生的錯誤。
- 解決方法: 先檢查該資料是否存在,再進行刪除。
錯誤訊息: phpinfo() has been disabled
PHP Warning: phpinfo() has been disabled for security reasons in /path/to/phpinfo.php on line xx
- 原因: 網管關閉使用 phpinfo
替代解決方法: 使用 console command
- /path/to/bin/php -i | grep "變數名稱" for Linux
- /path/to/bin/php -m 列出載入的模組[2]
錯誤訊息: PHP syntax error “unexpected $end”
解決方法
- 使用 Notepad++ctrl + b 檢查括弧是否封閉
- 使用 Sublime Textctrl + m 檢查括弧是否封閉
unified coding style
variable: $var
- PHP: starts with dollar symbol $var[3]
- javascript: the first character can be a letter or _ or $, and the other characters can be letters or _ or $ or numbers.[4]
troubleshooting steps of function
simply the question
- Is the function_exists? If not, looking for the alternative functions.
- Was the function really executed? Maybe using the __LINE__ to examin the logic.
- Disable the logical judgement and just print text
- Check the if-else condition was satisfied or not cf: Java: String Comparison It's logical (compiler will not show the warning) but wrong.
references
- ↑ php - Create a folder if it doesn't already exist - Stack Overflow code snippet: mkdir('path/to/directory', 0755, true);
- ↑ PHP: extension_loaded - Manual
- ↑ PHP: Basics - Manual
- ↑ , and the other characters can be letters or _ or $ or numbers.