Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need solution for logging private and protected object variables #28

Closed
GoogleCodeExporter opened this issue Jun 24, 2015 · 13 comments
Closed

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

This will be included in the next beta release.

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

  • Changed state: Accepted
  • Added labels: release-0.2

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Please try 0.2.b.3

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

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Never mind. I can reproduce it. Working on a fix.

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

@GoogleCodeExporter
Copy link
Author

Please try 0.2.b.4

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

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant