2

Is it possible to allow accessing private variables and members for debugging purpose.

Because, currently I am using GRPC and Protobuff in my PHP code. And when I try to dump or debug objects for GRPC communication I always get the following error

Fatal error: Cannot access private properties. in

And as a result I am not able to debug my application properly.

Please suggest what to do in that case

  • It would help if you showed code (a [mcve], specifically) that demonstrates what it is you're trying to do. – Mike 'Pomax' Kamermans Jul 29 '18 at 16:46
  • You can use `var_dump()` on the object you want to debug to show the properties of that object. – Progman Jul 29 '18 at 16:50
  • Possible duplicate of [Why can var\_dump ascertain values of private variables, yet it can't when trying to access a single the property](https://stackoverflow.com/questions/10249647/why-can-var-dump-ascertain-values-of-private-variables-yet-it-cant-when-trying) – Progman Jul 29 '18 at 16:51
  • Please edit your question to include the source code which throws the error. – Progman Jul 29 '18 at 21:40

1 Answers1

0

At least if you install xdebug, var_dump will list private properties of instances.

class Test
{
  private $x=1;
  private $y=2;
}

$test = new Test();

var_dump($test);

object(Test)[1]

private 'x' => int 1

private 'y' => int 2

You can even run PHP in single steps (trace mode) and inspect and manipulate any property and variable from within your IDE at runtime after each expression.

Pinke Helga
  • 6,378
  • 2
  • 22
  • 42