php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62073 different ways of iterating over an SplMaxHeap result in different keys
Submitted: 2012-05-19 16:50 UTC Modified: 2012-05-24 15:42 UTC
From: mr_platelet+jin6vr at fastmail dot fm Assigned: colder (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.13 OS: Debian Linux 6.0.4
Private report: No CVE-ID: None
 [2012-05-19 16:50 UTC] mr_platelet+jin6vr at fastmail dot fm
Description:
------------
If I use a foreach-loop to iterate over an SplMaxHeap,
the first key is 1.  If I use the "key" method, the
first key is 0.

Just in case it's relevant, this is the "configure"
command I used to compile PHP.  (Don't be misled by
the value for "prefix"; I'm using PHP 5.3.13, not
PHP 5.3.12.)

./configure  --prefix=/usr/local/php/5.3.12 --disable-cgi --with-
pgsql=shared,/usr --with-xmlrpc=shared --with-tidy=shared,/usr --with-
mssql=shared,/usr --with-sqlite=shared,/usr --with-snmp=shared,/usr --with-
xsl=shared,/usr --with-recode=shared,/usr --with-unixODBC=shared,/usr --with-
pspell=shared,/usr --with-mysqli=shared,/usr/bin/mysql_config --with-
mysql=shared,/usr --with-mcrypt=shared,/usr --with-ldap-sasl=/usr --with-
ldap=shared,/usr --with-t1lib=shared,/usr --with-ttf=shared,/usr --enable-
intl=shared --with-pdo-firebird=shared,/usr --with-interbase=shared,/usr --with-
imap-ssl --with-freetype-dir=shared,/usr --with-png-dir=shared,/usr --with-xpm-
dir=shared,/usr/X11R6 --with-jpeg-dir=shared,/usr --with-gmp=shared,/usr --
enable-gd-native-ttf --with-gd=shared,/usr --with-zlib-dir=/usr --with-
enchant=shared,/usr --with-curl=shared,/usr --without-mm --with-mhash=yes --
enable-zip --enable-soap --with-openssl=/usr --with-kerberos=/usr --with-zlib --
with-libxml-dir=/usr --enable-wddx --enable-sockets --enable-shmop --with-pcre-
regex=/usr --with-onig=/usr --enable-mbstring --with-gettext --enable-ftp --
enable-exif --with-iconv --without-gdbm --with-db4 --enable-ctype --with-bz2 --
enable-bcmath --enable-sysvmsg --enable-sysvshm --enable-sysvsem --enable-
calendar --with-pic --disable-static --disable-rpath --with-regex=php --disable-
debug --enable-pcntl --with-readline

Test script:
---------------
<?php
$heap = new SplMaxHeap;
$heap->insert(42);
foreach ($heap as $key => $value) {
  break;
}
var_dump($key);
var_dump($value);

$heap = new SplMaxHeap;
$heap->insert(42);
var_dump($heap->key());
var_dump($heap->current());

Expected result:
----------------
I expect to see 4 lines of output from the script,
and, among other things, I expect the third line to be
the same as the first line.

Actual result:
--------------
The script gives this output:

int(1)
int(42)
int(0)
int(42)

Note that the third line differs from
the first.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-20 17:48 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: colder
 [2012-05-23 13:01 UTC] reeze dot xia at gmail dot com
Hi, 
  This was introduced in http://svn.php.net/viewvc?view=revision&revision=269522,
SplHeap::key() get updated but leave foreach iterator unchanged.

I've sent a pull request at: https://github.com/php/php-src/pull/90

Thanks
 [2012-05-24 15:31 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=bde86a6639a661dcadb0ae4c3ce4cc8aca2a42b9
Log: Fixed bug #62073
 [2012-05-24 15:31 UTC] laruence@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9205c4fd62a769b7db3d00eccdf2ea35b20dd87f
Log: Fixed bug #62073 (Different ways of iterating over an SplMaxHeap result in different keys)
 [2012-05-24 15:35 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=bde86a6639a661dcadb0ae4c3ce4cc8aca2a42b9
Log: Fixed bug #62073
 [2012-05-24 15:35 UTC] laruence@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9205c4fd62a769b7db3d00eccdf2ea35b20dd87f
Log: Fixed bug #62073 (Different ways of iterating over an SplMaxHeap result in different keys)
 [2012-05-24 15:39 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=bde86a6639a661dcadb0ae4c3ce4cc8aca2a42b9
Log: Fixed bug #62073
 [2012-05-24 15:39 UTC] laruence@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9205c4fd62a769b7db3d00eccdf2ea35b20dd87f
Log: Fixed bug #62073 (Different ways of iterating over an SplMaxHeap result in different keys)
 [2012-05-24 15:42 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2012-05-24 15:42 UTC] laruence@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2014-10-07 23:25 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=bde86a6639a661dcadb0ae4c3ce4cc8aca2a42b9
Log: Fixed bug #62073
 [2014-10-07 23:25 UTC] stas@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=9205c4fd62a769b7db3d00eccdf2ea35b20dd87f
Log: Fixed bug #62073 (Different ways of iterating over an SplMaxHeap result in different keys)
 [2014-10-07 23:36 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=bde86a6639a661dcadb0ae4c3ce4cc8aca2a42b9
Log: Fixed bug #62073
 [2014-10-07 23:36 UTC] stas@php.net
Automatic comment on behalf of reeze.xia@gmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=9205c4fd62a769b7db3d00eccdf2ea35b20dd87f
Log: Fixed bug #62073 (Different ways of iterating over an SplMaxHeap result in different keys)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 04:01:30 2024 UTC