Reputation: 1671
I am having a little trouble with the print_r
function. Undoubtedly something I am misunderstanding in its operation... Basically, I have an array of objects in a class like so:
public $fields = array();
Assigned like so:
$oField = new Field();
/* property assignments to $oField omitted for brevity */
$this->fields[$i] = $oField;
Now in the primary class, I am attempting to capture debug information:
$this->debuginfo = print_r($this->fields, true);
When outputting the value of $this->debuginfo
, it simply says "Array" - basically not exploding the array. If I do a regular print_r($this->fields);
, it gives the expected results.
This is my first time attempting to use print_r
with it returning results versus outputting to the screen so I am sure I am just missing something, but in reading the php documentation, this is how it would seem to be implemented. What am I missing?
Thanks for any assistance!
Update:
print_r($var, true)
does indeed return the "exploded" variable properly as I had it written. Thanks to dev-null for their comment which gave me some food for thought that lead me to my problem.
Upvotes: 4
Views: 430
Reputation: 23
Try var_export() instead. var_export() gets structured information about the given variable.
example:
$this->debuginfo = var_export($this->fields, true);
Reference: http://php.net/manual/en/function.var-export.php
Upvotes: 1