15,024
edits
m (→檔案操作有關) |
|||
| Line 151: | Line 151: | ||
* Disable the logical judgement and just print text using [http://php.net/manual/en/function.var-dump.php var_dump] or [http://php.net/manual/en/function.print-r.php print_r] functions. | * Disable the logical judgement and just print text using [http://php.net/manual/en/function.var-dump.php var_dump] or [http://php.net/manual/en/function.print-r.php print_r] functions. | ||
* 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. | * 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. | ||
* | |||
== logging == | |||
native error logging | |||
* [http://www.php.net/ PHP] log: check the configuration file: /etc/php.ini (the location of configuration file can be verified by [http://php.net/manual/en/function.phpinfo.php phpinfo()] ) | |||
(for production site) unmark theese lines in the php.ini and restart Apache service | |||
<pre> | |||
log_errors = On | |||
error_log = "php_error.log" | |||
</pre> | |||
(for development site) using [http://php.net/manual/en/function.error-reporting.php error_reporting] | |||
<pre> | |||
error_reporting(E_ALL); | |||
</pre> | |||
[http://tw1.php.net/print_r PHP: print_r - Manual] | |||
<pre> | |||
$log = print_r($variable, true); | |||
//save to the log file | |||
$log = print_r(debug_backtrace(), true); | |||
//Generates a backtrace and save to the log file | |||
</pre> | |||
capture the result of var_dump: | |||
ob_start | |||
* [http://stackoverflow.com/questions/139474/how-can-i-capture-the-result-of-var-dump-to-a-string php - How can I capture the result of var_dump to a string? - Stack Overflow] | |||
* [http://php.net/manual/en/function.error-log.php PHP: error_log - Manual] | |||
<pre> | |||
ob_start(); | |||
var_dump($some_variable); | |||
$result = ob_get_clean(); | |||
error_log($result, 3, 'd:/result.log'); | |||
</pre> | |||
QuickForm | |||
<pre> | |||
$result = var_dump($some_variable); | |||
$form->addElement('html', $result); | |||
</pre> | |||
[http://ellislab.com/codeigniter CodeIgniter]: [http://stackoverflow.com/questions/7370391/how-to-configure-codeigniter-to-report-all-errors php - How to configure Codeigniter to report all errors? - Stack Overflow] | |||
show the line number and filename | |||
<pre> | |||
echo 'Houston, we've had a problem '. __line__ . ' ' . __FILE__ ."<br />"; | |||
</pre> | |||
more on [http://php.net/manual/en/language.constants.predefined.php PHP: Magic constants], [https://github.com/Seldaek/monolog monolog] | |||
== references == | == references == | ||