Array to string conversion error in PHP

后端 未结 3 822
遇见更好的自我
遇见更好的自我 2021-01-28 12:54

I have following code to backtrace the error ....but its

$traces = debug_backtrace();

foreach ($traces as $k => $v)
{
    if ($v[\'function\'] == \'include\         


        
相关标签:
3条回答
  • 2021-01-28 13:21

    You are not creating array properly

     $args .= $v['args'][$key];
    

    You are creating a string.

     $args = array(); 
                    if(isset($v['args']) && is_array($v['args']))
                    {
                        $size = count($v['args']);
                        foreach ($v['
                        args'] as $key => $arg)
                        {
                            array_push($args,$v['args'][$key]);
                           // some of your code
                    }
    
    0 讨论(0)
  • 2021-01-28 13:25
    $trace = debug_backtrace();
    foreach($traces as ...)
    

    There's something wrong here. $trace is a Debug Backtrace array. While you foreach($traces) ... which seems undefined. And you append to $traces which is supposed to be a non-scalar to foreach it.

    Just name your variables properly and make names different!

    0 讨论(0)
  • 2021-01-28 13:32

    you begin with:

    foreach($traces as $k=>$v) <- $traces here is an array
    

    then you try to do

    $traces.= "xxx" <- $traces here is handled as a string
    

    i would rather define a $tracestr string for aggregating text content.

    0 讨论(0)
提交回复
热议问题