是否有PHP调试器?哪些受欢迎?
答案 0 :(得分:8)
XDebug被认为是事实上的标准。其功能包括:
可以通过PECL安装:
pecl install xdebug
之后您必须将其添加到php.ini
:
zend_extension="/usr/local/php/modules/xdebug.so"
您也可以从源代码编译。完整说明here。
答案 1 :(得分:3)
答案 2 :(得分:-1)
有一些错误,我很抱歉。这是最终代码:
我正在编写一些代码来进行调试。也许对您有帮助:
debugRelated / plantillaDebugable.htm
<style>
#Debug
{
position:fixed;
bottom: 0;
right: 0;
max-height: 80vh;
overflow:auto;
overflow-x: hidden;
background: white;
text-align: left;
margin: auto;
-webkit-box-shadow: 6px 7px 0px -3px rgba(0,0,0,0.68);
-moz-box-shadow: 6px 7px 0px -3px rgba(0,0,0,0.68);
box-shadow: 6px 7px 0px -3px rgba(0,0,0,0.68);
border: 1px solid #aaa;
}
#Debug.Abierto
{
width: 100%;
left: 0;
}
#Debug h1.DebugableH1:hover
{
background: #900;
color: #eee;
}
#Debug h1.DebugableH1
{
padding-right: 20px;
background: #a22;
cursor: pointer;
-webkit-user-select: none; /* Chrome all / Safari all */
-moz-user-select: none; /* Firefox all */
-ms-user-select: none; /* IE 10+ */
user-select: none;
margin: 0;
height: 5vh;
font-size: 15pt;
text-align: right;
text-decoration: underline;
}
#Debug div.DebugableDiv
{
display: none;
max-height: 100vh;
overflow:auto;
border: 2px solid black;
padding: 15px;
background: #aaa;
}
#Debug div.DebugableDiv hr
{
margin: 30px;
border-top: 3px solid #900;
}
#Debug div.DebugableDiv p
{
font-size: 11pt;
font-weight: 600;
background: #fafafa;
padding: 2px 5px;
margin: 0 0 5px 0;
}
</style>
<script>
function actividadDebug()
{
$('#Debug .DebugableDiv').hide();
$('#Debug').removeClass('Abierto');
$('#Debug').click(e=>{e.preventDefault(); return false;});
$('#Debug h1').click((e)=>
{
e.preventDefault();
$('#Debug .DebugableDiv').toggle();
$('#Debug').toggleClass('Abierto');
return false;
});
$(document).click(()=>
{
$('#Debug .DebugableDiv').hide();
$('#Debug').removeClass('Abierto');
});
}
</script>
<div id='Debug'>
<h1 class='DebugableH1'></h1>
<div class='DebugableDiv'>{output}</div>
<script>actividadDebug();</script>
</div>
debugRelated / enunciados.json
{
"titulos":
{
"nombreTitulo": "Debug de '%s' - <strong>%s: </strong>",
"nombre": "Debug de '%s': ",
"titulo": "<strong>%s: </strong>"
},
"array":"<pre style=\"margin:5px;background:#f8f8f8; padding:10px 20px; border: 2px solid black\"><h3 style=\"font:600 12pt courier new; margin: 0\">%s</h3>%s</pre>",
"simple":"<p>%s%s</p>"
}
debug.php
<!DOCTYPE html>
<html lang="es">
<head>
<title>{tituloPagina} - {sloganPagina}</title>
<meta charset="UTF-8">
<meta name="title" content="{tituloPagina} - {sloganPagina}">
<meta id='metaPagDescripcion' name="description" content="{descripcionPagina}">
<meta name="keywords" content="{keywordsPagina}">
<meta name="author" content="Alexis Leite - alexisleite@live.com">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="Jquery.js"></script>
</head>
<body>
<?php
class DebugBuffer
{
private static $buffer = '';
private static $plantilla;
private static $inst;
public function load()
{
Static::$plantilla = file_get_contents(__DIR__ . '/DebugRelated/plantillaDebugable.htm');
}
public static function escribir($que)
{
Static::$buffer .= $que;
}
public static function output()
{
return str_replace("{output}", Static::$buffer, Static::$plantilla);
}
}
DebugBuffer::load();
class DebugStruct
{
private static $estructura;
public static function get()
{
if(!Static::$estructura) Static::$estructura = json_decode(file_get_contents(__DIR__ . '/DebugRelated/enunciados.json'));
return Static::$estructura;
}
}
/**
* Clase para escritor html.
*/
class Debugable
{
// El nombre que se mostrara en el debug
protected $debugName;
// Se hace debug o no
protected $debug = true;
// El nivel al que se hace debug
protected $debugLevel = 1;
// Solo ese nivel o todos los niveles inferiores tambien
protected $debugStrict = false;
public function debug($level,$que,$titulo='')
{
if(!$this->debug
|| $this->debugStrict && $level != $this->debugLevel
|| !$this->debugStrict && $level > $this->debugLevel)
return;
$tit = '';
if(isset($this->debugName) && $titulo != '')
$tit .= sprintf(DebugStruct::get()->titulos->nombreTitulo,$this->debugName,$titulo);
else if(isset($this->debugName))
$tit .= sprintf(DebugStruct::get()->titulos->nombre,$this->debugName);
else if($titulo != '')
$tit .= sprintf(DebugStruct::get()->titulos->titulo,$titulo);
if(is_array($que) || is_object($que))
{
$output = sprintf(DebugStruct::get()->array,$tit,print_r($que, true));
}
else
$output = sprintf(DebugStruct::get()->simple,$tit,$que);
DebugBuffer::escribir($output . PHP_EOL);
}
}
class Test extends Debugable
{
protected $debug = true;
protected $debugName = 'Prueba';
protected $debugLevel = 1;
protected $debugStrict = false;
public function __construct()
{
$arr =
[
'a' =>
[
'aa' => 'aa',
'ab' => 'ab'
],
'b' =>
[
'ba' => 'ba',
'bb' => [1,2,3,4,5,6,7]
]
];
$this->debug(1,'Prueba','Titulo');
$this->debug(1,$arr,'Array de prueba');
echo DebugBuffer::output();
}
}
new Test();
?>
</body>
</html>
我之所以这样,是因为您可以指定是否要调试此类(受保护的$ debug),要使用的输出名称(受保护的$ debugName),要调试的级别($ debugLevel),如果调试严格到($ debugStrict)级别。
请参阅
$this->debug(1,'Prueba','Titulo');
数字1是您要调试的级别。 调试级别意味着:
以下几行中定义了
: if(!$this->debug
|| $this->debugStrict && $level != $this->debugLevel
|| !$this->debugStrict && $level > $this->debugLevel)
return;
最后,输出代码唯一要做的就是调用
DebugBuffer::output()
有任何疑问,请问我。我将附上屏幕截图
The screenshot of my debugger working
您可能会注意到,您需要放置一个名为jquery.js的文件才能使其正常工作,您无法将此引用更改为jquery文件的路径