Print_r Return Value Invalid

I have a little problem with print_r function. Undoubtedly, I don’t understand something in his work ... Basically, I have an array of objects in this class:

 public $fields = array(); 

Assigned as follows:

 $oField = new Field(); /* property assignments to $oField omitted for brevity */ $this->fields[$i] = $oField; 

Now in the main class I am trying to get debugging information:

 $this->debuginfo = print_r($this->fields, true); 

When the value of $this->debuginfo it simply says "Array" - basically the array does not explode. If I do the usual print_r($this->fields); It gives the expected results.

This is my first time I try to use print_r to return results or display on the screen, so I'm sure I just missed something, but when reading the php documentation this is like how it will be implemented. What am I missing?

Thanks for any help!

Update: print_r($var, true) really returns the β€œexploded” variable properly, as I wrote it. Thanks to dev-null for their comment, which gave me some food for thought that led me to my problem.

+4
source share
1 answer

Try var_export () . var_export () gets structured information about this variable.

Example:

 $this->debuginfo = var_export($this->fields, true); 

Link: http://php.net/manual/en/function.var-export.php

+1
source

All Articles