|  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
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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
43 + 34 = ?
Subscribe to this entry?

 [2015-01-28 15:21 UTC] tulpetulpe at fastmail dot fm
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';


// outputs int(1) instead of the expected object

Expected result:
Dump of the object $o

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-28 15:26 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: colder
 [2015-01-28 15:26 UTC]
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]
-Status: Verified +Status: Closed
 [2016-01-11 16:19 UTC]
This has been fixed in the latest version of php-weakref (available only for PHP7)
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Feb 25 17:01:24 2021 UTC