lgyers / firephp

Automatically exported from code.google.com/p/firephp
0 stars 0 forks source link

Need solution for logging private and protected object variables #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Only public object variables get logged. Need to find a solution to log
private and protected variables as well.

Original issue reported on code.google.com by christ...@christophdorn.com on 11 Sep 2008 at 6:01

GoogleCodeExporter commented 9 years ago
Here is a proof of concept using var_export().

<?php

class Dumper
{
  public static function __set_state($class, $members)
  {    
    $dump = array('__className'=>$class);
    foreach( $members as $name => $value ) {
      $dump[$name] = $value;
    }
    return $dump;
  }
}

class TestObject
{
  var $publicVar = 'Public Var';
  protected $protectedVar = 'Protected Var';
  private $privateVar = 'PrivateVar';
}

$obj = new TestObject();

$code = var_export($obj, true);

$code = str_replace('TestObject::__set_state(',
                    'Dumper::__set_state(\'TestObject\',', $code);

echo '<pre>';
echo $code;
echo '</pre>';

eval('$dump = ' . $code . ';');

echo '<pre>';
var_dump($dump);
echo '</pre>';

?>

Original comment by christop...@gmail.com on 16 Sep 2008 at 8:29

GoogleCodeExporter commented 9 years ago
This will be included in the next beta release.

Original comment by christop...@gmail.com on 6 Oct 2008 at 8:36

GoogleCodeExporter commented 9 years ago
hi Cristoph,
I suggest using the parseObject() function in the comments here:
http://es2.php.net/manual/en/function.get-object-vars.php

Original comment by krom...@gmail.com on 7 Oct 2008 at 9:50

GoogleCodeExporter commented 9 years ago
Take a look at:

http://code.google.com/p/firephp/source/browse/trunk/DevApp/application/bootstra
p/plain/LogPrivateObjectMembers.php

That is my planned implementation.

I think it will do the job just fine. I don't quite like parsing the output of 
print_r.

Original comment by christop...@gmail.com on 7 Oct 2008 at 10:42

GoogleCodeExporter commented 9 years ago

Original comment by christ...@christophdorn.com on 7 Oct 2008 at 12:34

GoogleCodeExporter commented 9 years ago
Hi Christoph. I just tried the new 0.2.b.2.
You export the object via var_export. Thats fine, but does not work with bigger 
vars
and does not handle recursions. Perhaps its possible to parse the ouptut of
serialize()? I think thats the only working solution for every case. Otherwise 
it is
not possible to use it with big objects.

Original comment by fritz...@gmail.com on 8 Oct 2008 at 3:44

GoogleCodeExporter commented 9 years ago
I found a better solution using a cast to array. (array)$obj

I'll have an update available ASAP.

Original comment by christ...@christophdorn.com on 8 Oct 2008 at 8:24

GoogleCodeExporter commented 9 years ago
Please try 0.2.b.3

Original comment by christ...@christophdorn.com on 8 Oct 2008 at 11:15

GoogleCodeExporter commented 9 years ago
Using the following code:
<?php
require_once 'FirePHPCore/fb.php';
$obj1 = new stdClass;
$obj2 = new stdClass;
$obj1->p = $obj2;
$obj2->p = $obj1;
FB::log($obj1);

I'm getting a PHP error:
Fatal error: Nesting level too deep - recursive dependency? in
/usr/share/php/FirePHPCore/FirePHP.class.php on line 680
Call Stack
#   Time    Memory  Function    Location
1   0.0529  55784   {main}( )   ../test.php:0
2   0.2829  312464  FB::log( )  ../test.php:7
3   0.2829  312800  FB::send( ) ../fb.php:115
4   0.2831  314204  call_user_func_array ( )    ../fb.php:81
5   0.2831  314844  FirePHP->fb( )  ../fb.php:0
6   0.3384  318636  FirePHP->jsonEncode( )  ../FirePHP.class.php:549
7   0.3385  318636  FirePHP->encodeObject( )    ../FirePHP.class.php:657
8   0.3768  319372  FirePHP->encodeObject( )    ../FirePHP.class.php:740
9   0.3768  319720  in_array ( )    ../FirePHP.class.php:680

Original comment by jaap.t...@gmail.com on 8 Oct 2008 at 11:23

GoogleCodeExporter commented 9 years ago
Are you using version 0.2.b.3 of the FirePHPCore library?

Original comment by christ...@christophdorn.com on 8 Oct 2008 at 11:46

GoogleCodeExporter commented 9 years ago
Never mind. I can reproduce it. Working on a fix.

Original comment by christ...@christophdorn.com on 8 Oct 2008 at 11:50

GoogleCodeExporter commented 9 years ago
Please try 0.2.b.4

Original comment by christ...@christophdorn.com on 9 Oct 2008 at 12:10

GoogleCodeExporter commented 9 years ago

Original comment by christ...@christophdorn.com on 22 Oct 2008 at 5:11