0

I am very interested in @Sebastián Grignoli 's answer to this question but, when I try to execute it, I get Fatal error: Class 'dInspect' not found.

Can anyone tell me how to rectify this? Thanks.

Community
  • 1
  • 1
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551

3 Answers3

1

As far as I can tell, it's some class he made. I googled and the only thing that comes up for "php dInspect" is this question..I also looked for member functions called "dump" in php-included libraries and found nothing.

You might be able to modify his answer a bit to get what you want, it looks pretty complete. (I didn't test anything though)

LainIwakura
  • 2,871
  • 2
  • 19
  • 22
1

Here's a simplified version of the solution. Maybe you could adapt it to your needs with less trouble:

function catch_param($label)
{
        $bt = debug_backtrace();
        $src = file($bt[0]["file"]);
        $line = $src[ $bt[0]['line'] - 1 ];

        // let's match the function call and the last closing bracket
        preg_match( "#catch_param\((.+)\)#", $line, $match );

        /* let's count brackets to see how many of them actually belongs 
           to the var name
           Eg:   die(catch_param($this->getUser()->hasCredential("delete")));
                  We want:       $this->getUser()->hasCredential("delete")
        */
        $max = strlen($match[1]);
        $varname = "";
        $c = 0;
        for($i = 0; $i < $max; $i++){
            if(     $match[1]{$i} == "(" ) $c++;
            elseif( $match[1]{$i} == ")" ) $c--;
            if($c < 0) break;
            $varname .=  $match[1]{$i};
        }

    // $varname now holds the name of the passed variable ('$' included)
    // Eg:   catch_param($hello) 
    //             => $varname = "$hello"
    // or the whole expression evaluated
    // Eg:   catch_param($this->getUser()->hasCredential("delete"))
    //             => $varname = "$this->getUser()->hasCredential(\"delete\")"

    echo("The passed expression is: ".$varname);

}

If what you want is the inspection class, this is the download link:

http://download.inspect.jaku.com.ar/

Here's an example of the inspector function (and my dInspect class) in action:

http://inspect.jaku.com.ar/

Texts are in spanish in that page, but code is concise and really easy to understand.

Sebastián Grignoli
  • 32,444
  • 17
  • 71
  • 86
0

When I google it, the first hit is a reference to the NuSphere debugger nusphere.com/products/php_debugger.htm since I don't have that, it looks like I am SOL.

Sebastián Grignoli
  • 32,444
  • 17
  • 71
  • 86
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • My answer has nothing to do with the Nusphere debugger. I never heard of it before. I updated the original answer to avoid the confusing function call. – Sebastián Grignoli Jul 26 '11 at 23:17