PHP 8.5.0 Alpha 4 available for testing

Voting

: max(eight, eight)?
(Example: nine)

The Note You're Voting On

manuelguzman dot villar at gmail dot com
1 month ago
WeakMap and SplObjectStorage have different behavior when iterating in a foreach loop. While the key in SplObjectStorage is the numeric index of the inner array, in the WeakMap the key is the object reference:

<?php
class A {}

$a = new A;

$objectStorage = new SplObjectStorage ();
$weakMap = new WeakMap();

$objectStorage [$a] = 1;
$weakMap[$a] = 1;

foreach(
$objectStorage as $key => $value) {
var_dump($key); // prints: int(0)
}

foreach(
$weakMap as $key => $value) {
var_dump($key); // prints: object(A)#1 (0) {}
}

<< Back to user notes page

To Top