Re: serialize bug with array that references to itself?
| From: | Jochem Maas | Date: | Wed, 03 Nov 2004 18:35:14 +0000 |
| Subject: | Re: serialize bug with array that references to itself? | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13719@lists.php.net to get a copy of this message | ||
Hi Andrey,
I have to confess my understanding of the engine internals is next to zero, but I do understand that var_dump and print_r were created with/for different pretexts.
I agree with you that printing nothing for NULL is doesn't feel right (btw boolean false has the same effect) - this can be problematic when you don't know that this is the case (indeed much time have I lost on this issue when I first started out), this is a minor gripe and easily sidestepped with a var_dump :-)
my question was more out of curiosity (although I would like to see the threshold for var_dump dropped to 2 if that is technically feasible/acceptable) - there may be a good reason for the difference in thresholds, it may be a an oversight/inconsistency. either way my motive is to better understand the reasoning behind the way things work in PHP - better understanding how/why a developer made it work a certain has in the past really helped me improve my code.
thanking everyone who has made (and continues to make) PHP what it is - it rocks alot more than it doesn't ;-).
Andrey Hristov wrote:
Hi, print_r() and var_dump() are quite different in their nature. print_r() is a thin wrapper around an internal Zend function (as far as I remember) while var_dump() is in ext/standard/var.c The do more or less the same job still some differences in the output (print_r() shows nothing on NULL variables which I find clumsy since lack of output where I expect ouput makes me suspicious). Andrey Jochem Maas wrote:Andrey Hristov wrote:Well, when there is traversion inside the engine, it checks whether it has processed a "node" already several times. As far as I remember the threshold is 3. So once it goes over $Arr, the counter increases to 1, the second time to 2 and third time it is 3 and ZE reports recursion.is there good reason to set the threshold at 3 iso 2? when dumping out objects that make heavy use of 'parent' references this leads to tons of extra output which would be greatly cutdown if the threshold was 2 iso 3. just to make the point, print_r seems to use a threshold of 2 (which is why I always try print_r before taking my chances with var_dump): <?php class a { public $self; } $A = new a; $A->self = $A; var_dump( $A ); print_r( $A ); ?>HTH, Andrey Francisco M. Marzoa Alonso wrote:BTW., I'm not sure that there's nothing more wrong here. Takin the first part of the code of first example: <?php $Arr = array(); $Arr['self'] = &$Arr; var_dump ( $Arr ); ?> It returns: array(1) { ["self"]=> array(1) { ["self"]=> *RECURSION* } } Is that as its expected to be? I meant that perhaps it should be: array(1) { ["self"]=> *RECURSION* } Since the element in $Arr['self'] is yet (or at least should be) a reference to itself...