ID:               36219
 User updated by:  bdhook at gmail dot com
 Reported By:      bdhook at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Slackware 10.2
 PHP Version:      5.1.2
 New Comment:

Turns out this was a bug in my code. The code went through several
revisions, and at one point the argument to the function was changed so
that it was not by reference. This caused the function to get a *copy*
of the root node at start, and get the proper reference after cycling
through the code a few times. Adding a & in the correct place caused
the code to function as expected without the "fix" line.


Previous Comments:
------------------------------------------------------------------------

[2006-01-31 02:50:30] bdhook at gmail dot com

Description:
------------
I have been writing some code to handle Modified Pre-ordered Tree
Traversal data, and the sole purpose of the code is to avoid recursive
calls. The code works, but I found I had to place a line in that should
not need to be there.

My arrays are nested, but by reference rather than as usual. Each item
with children has a member array called 'children', with each value
bein a reference to a child. Each child has a member called 'parent',
which has a reference to the parent array. The problem is, my code
(which functions by using internal array pointers) doesn't work
properly until the array is copied by reference back into itself. The
code posted on my website (which will remain up as long as I don't have
an answer) demonstrates this, though it needs a populated database with
an MPTT tree to see it in action.

The line $array=&$array['children'][0]['parent']; should not need to be
there. But, if you remove it, the code doesn't function correctly until
after its natural cycle brings it back up to the root node, which
effectively mimics the by reference assignment. At this point in the
code the counter is already thrown off.

Note that $array=&$array; did not seem to work to fix the problem.

Reproduce code:
---------------
http://www.coder7.com/mptt.phps

Expected result:
----------------
The code generates the expected output, but only because a work-around
has been put in.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=36219&edit=1

Reply via email to