From:             bdhook at gmail dot com
Operating system: Slackware 10.2
PHP version:      5.1.2
PHP Bug Type:     Arrays related
Bug description:  By Reference nested arrays

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 bug report at http://bugs.php.net/?id=36219&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36219&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36219&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36219&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36219&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36219&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36219&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36219&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36219&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36219&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36219&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36219&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36219&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36219&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36219&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36219&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36219&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36219&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36219&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36219&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36219&r=mysqlcfg

Reply via email to