php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68934 WeakMap::key() returns integer instead of object
Submitted: 2015-01-28 15:21 UTC Modified: 2016-01-11 16:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: tulpetulpe at fastmail dot fm Assigned: colder (profile)
Status: Closed Package: Weakref (PECL)
PHP Version: 5.6.5 OS: Mac OS X 10.9.5
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tulpetulpe at fastmail dot fm
New email:
PHP Version: OS:

 

 [2015-01-28 15:21 UTC] tulpetulpe at fastmail dot fm
Description:
------------
WeakRef Vesion: 0.2.6
Configure line: --with-pdo-mysql --enable-mbstring --with-openssl

The documentation states that the ::key() method returns an object.
However in my test script it returns an integer.

Also in a foreach loop the key is just an integer, never the object. I also couldn't find any other way to get the objects back out of the WeakMap.

PS: Thanks for the great extension and the support!

Test script:
---------------
$o = new stdClass();

$wm = new WeakMap();
$wm[$o] = 'foo';

$wm->rewind();

// outputs int(1) instead of the expected object
var_dump($wm->key());

Expected result:
----------------
Dump of the object $o

Actual result:
--------------
int(1)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-28 15:26 UTC] colder@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: colder
 [2015-01-28 15:26 UTC] colder@php.net
The general issue is that foreach($wm as $k => $o) originally did not support keys other than int/string in PHP (this is an engine limitation of PHP <5.5).

Now that it does support these, I should release a version of WeakMap that does this in foreach.
 [2015-01-28 15:40 UTC] tulpetulpe at fastmail dot fm
I understand, thanks. Is there any other way or work around to get the values out of the WeakMap again?
 [2016-01-11 16:19 UTC] colder@php.net
-Status: Verified +Status: Closed
 [2016-01-11 16:19 UTC] colder@php.net
This has been fixed in the latest version of php-weakref (available only for PHP7)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC