PHP is a server-side scripting language used to develop dynamic Web applications. There is no good server-side debugging tool that is one of its limitations compared to Java. Usually we are in the PHP code to add Echo, var_dump and other statements, the variable, the value of the array is displayed in the browser to achieve the purpose of debugging.
Now, more and more browsers have developed the tool or JavaScript console, through which we can easily display the PHP code in the variable or array values. Let's do an example here. The PHP code in the example has four tracking levels: info, warn, log, error, developers can use the browser console to display error variables, array values.
Copy the code below into the PHP file and save it as webconsole.php
Copy CodeThe code is as follows:
Class Webconsole {
private static function Write ($data, $type = ' info ') {
$method _types = Array (' ERROR ', ' info ', ' log ', ' warn ');
$msg _type = "; (Ps:t good PHP Q-button 峮: 304224365, verify: CSL)
if (In_array ($type, $method _types)) {
$msg _type = sprintf ("console.%s", $type);
}else {
$msg _type = sprintf ("console.%s", ' info ');
}
if (Is_array ($data)) {
Echo ("");
} else {
Echo ("");
}
}
public static function info ($data) {
Self::write ($data);
}
public static function error ($DATA) {
Self::write ($data, ' Error ');
}
public static function log ($data) {
Self::write ($data, ' log ');
}
public static function warn ($data) {
Self::write ($data, ' warn ');
}
}
?>
Now, import the Webconsole class and use the trace feature.
Copy CodeThe code is as follows:
Require_once (' webconsole.php ');
$fruits = Array (' Apple ', ' mange ', ' banana ');
Webconsole::log ($fruits);
Webconsole::info ($fruits);
Webconsole::warn ($fruits);
Webconsole::error ($fruits);
?>
Now open your browser console and you will notice that a screen similar to the following appears:
http://www.bkjia.com/PHPjc/676884.html www.bkjia.com true http://www.bkjia.com/PHPjc/676884.html techarticle PHP is a server-side scripting language used to develop dynamic Web applications. There is no good server-side debugging tool that is one of its limitations compared to Java. Usually we are in PHP code ...