为什么getTrace()赢了';OOP php中的公共方法不起作用
我正在尝试使用下面所示的代码制作一个自定义调试器,它对受保护的和私有的方法很好,但对公共方法不起作用。你能帮忙吗为什么getTrace()赢了';OOP php中的公共方法不起作用,php,Php,我正在尝试使用下面所示的代码制作一个自定义调试器,它对受保护的和私有的方法很好,但对公共方法不起作用。你能帮忙吗 class newTrace{ public $showTrace = false; function GetCallingMethodName(){ if($this->showTrace){ $e = new Exception(); $traceArr = $e->getTrace(); $trace
class newTrace{
public $showTrace = false;
function GetCallingMethodName(){
if($this->showTrace){
$e = new Exception();
$traceArr = $e->getTrace();
$trace = $traceArr[2];
$traceMsg = $trace['class'] .'::'. $trace['function'] .' args:'. json_encode($trace['args']) .' in '. str_replace("\\", "/", $trace['file']) .' ['. $trace['line'] .']';
echo "<script>console.log('". $traceMsg ."')</script>";
}
}
function logMsg($msg){
if($this->showTrace){
echo '<script>console.log("'. $msg .'")</script>';
}
}
function showTrace(){
$this->showTrace = true;
}
private function methodOne($arg1, $arg2){
echo 'in methodOne<br>';
$this->logMsg('this is a sample message');
}
public function methodTwo($arg){
echo 'in methodTwo<br>';
}
protected function methodThree(){
echo 'in methodThree<br>';
}
public function __call($method, $arguments) {
if(method_exists($this, $method)) {
$this->GetCallingMethodName();
return call_user_func_array(array($this,$method),$arguments);
}
}
}
$a = new newTrace;
$a->showTrace();
$a->methodOne('arg1', ['arg2']);
$a->methodTwo(12);
$a->methodThree();
class-newTrace{
public$showTrace=false;
函数GetCallingMethodName(){
如果($this->showTrace){
$e=新异常();
$traceArr=$e->getTrace();
$trace=$tracerr[2];
$traceMsg=$trace['class'].:'.$trace['function'].'args:'.json\u encode($trace['args']).in.str\u replace(“\\”,“/”,$trace['file'])。['.$trace['line'].];
echo“console.log(''.$traceMsg.')”;
}
}
函数logMsg($msg){
如果($this->showTrace){
echo'console.log(“.$msg.”);
}
}
函数showTrace(){
$this->showTrace=true;
}
私有函数methodOne($arg1,$arg2){
回声“在methodOne中
”;
$this->logMsg('这是一条示例消息');
}
公共函数方法二($arg){
回声“在方法二
中”;
}
受保护的函数methodThree(){
回音“方法三
”;
}
公共函数调用($method,$arguments){
如果(方法_存在($this$method)){
$this->GetCallingMethodName();
返回call\u user\u func\u数组(数组($this$method),$arguments);
}
}
}
$a=新的纽特种族;
$a->showTrace();
$a->methodOne('arg1',['arg2']);
$a->methodTwo(12);
$a->methodThree();
以下是一个示例输出:
您的代码片段也会链接到您的屏幕截图。无论如何,请在这里发布代码。对不起,链接放错了地方,我已经在这里添加了代码片段。请看一看@rjdown。您的代码片段似乎也链接到了您的屏幕截图。无论如何,请在这里发布代码。对不起,链接放错了地方,我已经在这里添加了代码片段。请看一下@rjdown