From: s dot lystsev at gmail dot com
Operating system: Fedora Core release 1
PHP version: 5.0.4
PHP Bug Type: Scripting Engine problem
Bug description: Strange order of array elements if there are constants among
array keys
Description:
------------
If I initialize array immediately when declaring it as a class member (see
"Reproduce code") and there are some constants among array keys, then the
order of array elements is broken. All the elements which have a constant
as a key - they are moved to the end of an array. Thus the declared order
of elements is broken.
If I move initialization of array to some method (e.g. in class
constructor) - everything works as expected, array is not reordered.
Well, the bug is close to Bug #28072, but there was a talk about static
arrays. In my case the array was not static.
Reproduce code:
---------------
define ('baa', '_a_');
define ('baz', '_b_');
class T {
var $test = array(
baa => 'xx',
'bbb' => 'x1',
'aaa' => 'x0',
'ccc' => 'x2',
baz => 'yy'
);
function process() {
foreach ($this->test as $x => $y) {
echo "$x => $y\n";
}
}
}
$t = new T();
$t->process();
Expected result:
----------------
_a_ => xx
bbb => x1
aaa => x0
ccc => x2
_b_ => yy
Actual result:
--------------
bbb => x1
aaa => x0
ccc => x2
_a_ => xx
_b_ => yy
--
Edit bug report at http://bugs.php.net/?id=33905&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33905&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=33905&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=33905&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33905&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33905&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33905&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33905&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33905&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33905&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33905&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=33905&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=33905&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33905&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33905&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33905&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33905&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33905&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33905&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33905&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33905&r=mysqlcfg