Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Zend/tests/enum/spl-object-storage.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ $storage[Foo::Baz] = 'Baz';
var_dump($storage[Foo::Bar]);
var_dump($storage[Foo::Baz]);

var_dump($storage->contains(Foo::Bar));
var_dump($storage->contains(Foo::Qux));
var_dump($storage->offsetExists(Foo::Bar));
var_dump($storage->offsetExists(Foo::Qux));

$serialized = serialize($storage);
var_dump($serialized);
Expand Down
1 change: 1 addition & 0 deletions ext/spl/spl_observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "zend_smart_str.h"
#include "zend_interfaces.h"
#include "zend_exceptions.h"
#include "zend_attributes.h"

#include "php_spl.h" /* For php_spl_object_hash() */
#include "spl_observer.h"
Expand Down
3 changes: 3 additions & 0 deletions ext/spl/spl_observer.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ public function notify(): void;
class SplObjectStorage implements Countable, SeekableIterator, Serializable, ArrayAccess
{
/** @tentative-return-type */
#[\Deprecated(since: '8.5', message: "use method SplObjectStorage::offsetSet() instead")]
public function attach(object $object, mixed $info = null): void {}

/** @tentative-return-type */
#[\Deprecated(since: '8.5', message: "use method SplObjectStorage::offsetUnset() instead")]
public function detach(object $object): void {}

/** @tentative-return-type */
#[\Deprecated(since: '8.5', message: "use method SplObjectStorage::offsetExists() instead")]
public function contains(object $object): bool {}

/** @tentative-return-type */
Expand Down
30 changes: 26 additions & 4 deletions ext/spl/spl_observer_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions ext/spl/tests/SplObjectStorage/SplObjectStorage_coalesce.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ var_dump(isset($s[$o2]));
var_dump(empty($s[$o2]));
$s[$o2] = null;
var_dump($s[$o2] ?? new stdClass());
echo "check isset/empty/contains for null. offsetExists returns true as long as the entry is there.\n";
echo "check isset/empty/contains/offsetExists for null. offsetExists returns true as long as the entry is there.\n";
var_dump(isset($s[$o2]));
var_dump(empty($s[$o2]));
var_dump($s->contains($o2));
echo "check isset/empty/contains for false.\n";
var_dump($s->offsetExists($o2));
echo "check isset/empty/contains/offsetExists for false.\n";
$s[$o2] = false;
var_dump(isset($s[$o2]));
var_dump(empty($s[$o2]));
var_dump($s->contains($o2));
var_dump($s->offsetExists($o2));
try {
$s['invalid'] = 123;
} catch (Error $e) {
Expand Down Expand Up @@ -56,18 +58,24 @@ bool(false)
bool(true)
object(stdClass)#4 (0) {
}
check isset/empty/contains for null. offsetExists returns true as long as the entry is there.
check isset/empty/contains/offsetExists for null. offsetExists returns true as long as the entry is there.
bool(true)
bool(true)

Deprecated: Method SplObjectStorage::contains() is deprecated since 8.5, use method SplObjectStorage::offsetExists() instead in %s on line %d
bool(true)
bool(true)
check isset/empty/contains for false.
check isset/empty/contains/offsetExists for false.
bool(true)
bool(true)

Deprecated: Method SplObjectStorage::contains() is deprecated since 8.5, use method SplObjectStorage::offsetExists() instead in %s on line %d
bool(true)
bool(true)
TypeError: SplObjectStorage::offsetSet(): Argument #1 ($object) must be of type object, string given
TypeError: SplObjectStorage::offsetExists(): Argument #1 ($object) must be of type object, string given

Notice: Indirect modification of overloaded element of SplObjectStorage has no effect in %s on line 38
Notice: Indirect modification of overloaded element of SplObjectStorage has no effect in %s on line %d
object(SplObjectStorage)#1 (1) {
["storage":"SplObjectStorage":private]=>
array(2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ $b = (object) 'b';
$c = (object) 'c';

$foo = new SplObjectStorage;
$foo->attach($a);
$foo->attach($b);
$foo->offsetSet($a);
$foo->offsetSet($b);

$bar = new SplObjectStorage;
$bar->attach($b);
$bar->attach($c);
$bar->offsetSet($b);
$bar->offsetSet($c);

$foo->removeAllExcept($bar);
var_dump($foo->contains($a));
var_dump($foo->contains($b));
var_dump($foo->offsetExists($a));
var_dump($foo->offsetExists($b));

?>
--EXPECT--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ var_dump($storage->current());

echo "--- With holes cases ---\n";

$storage->detach($b);
$storage->detach($d);
$storage->offsetUnset($b);
$storage->offsetUnset($d);

foreach (range(0, 2) as $index) {
$storage->seek($index);
Expand Down
4 changes: 2 additions & 2 deletions ext/spl/tests/SplObjectStorage/bug49263.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ $o2 = new stdClass;

$s = new SplObjectStorage();

$s->attach($o1, array('prev' => 2, 'next' => $o2));
$s->attach($o2, array('prev' => $o1));
$s->offsetSet($o1, array('prev' => 2, 'next' => $o2));
$s->offsetSet($o2, array('prev' => $o1));

$ss = serialize($s);
unset($s,$o1,$o2);
Expand Down
4 changes: 2 additions & 2 deletions ext/spl/tests/SplObjectStorage/bug53071.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function LimitedScope()
$myB = new SplObjectStorage();
$myC = new myClass();
$myC->member = $myA; // myC has a reference to myA
$myB->Attach($myC); // myB attaches myC
$myA->member = $myB; // myA has myB, comleting the cycle
$myB->offsetSet($myC); // myB attaches myC
$myA->member = $myB; // myA has myB, completing the cycle
}
LimitedScope();
var_dump(gc_collect_cycles());
Expand Down
2 changes: 1 addition & 1 deletion ext/spl/tests/SplObjectStorage/bug67582.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MyObjectStorage extends SplObjectStorage {
class TestObject {}

$list = new MyObjectStorage();
$list->attach(new TestObject());
$list->offsetSet(new TestObject());

foreach($list as $x) var_dump($list->offsetExists($x));

Expand Down
2 changes: 1 addition & 1 deletion ext/spl/tests/SplObjectStorage/bug69108.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $b = new SplObjectStorage();
for ($i = 10000; $i > 0; $i--) {
$object = new StdClass();
$a[] = $object;
$b->attach($object);
$b->offsetSet($object);
}

$c = serialize(array($a, $b));
Expand Down
2 changes: 1 addition & 1 deletion ext/spl/tests/SplObjectStorage/bug69227.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ zend.enable_gc=1
<?php

$s = new SplObjectStorage();
$s->attach($s);
$s->offsetSet($s);
gc_collect_cycles();
echo "ok";
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $b = new SplObjectStorage();
for ($i = 10000; $i > 0; $i--) {
$object = new StdClass();
$object->a = str_repeat("a", 2);
$b->attach($object);
$b->offsetSet($object);
}
?>
--EXPECTF--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ class SubjectImpl implements SplSubject
function attach(SplObserver $observer): void
{
echo $this->name . '->' . __METHOD__ . '(' . $observer->getName() . ");\n";
$this->observers->attach($observer);
$this->observers->offsetSet($observer);
}

function detach(SplObserver $observer): void
{
echo $this->name . '->' . __METHOD__ . '(' . $observer->getName() . ");\n";
$this->observers->detach($observer);
$this->observers->offsetUnset($observer);
}

function count(): int
Expand All @@ -100,7 +100,7 @@ class SubjectImpl implements SplSubject

function contains($obj)
{
return $this->observers->contains($obj);
return $this->observers->offsetExists($obj);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $storage = new SplObjectStorage();

foreach(array(1,"2","foo",true) as $value)
{
$storage->attach(new TestClass($value));
$storage->offsetSet(new TestClass($value));
}

var_dump(count($storage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $storage = new MyStorage();

foreach(array(1,2) as $value)
{
$storage->attach(new TestClass($value));
$storage->offsetSet(new TestClass($value));
}

var_dump(count($storage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $storage = new MyStorage(1,2,3);

foreach(array(array(4,5,6),array(7,8,9)) as $value)
{
$storage->attach(new TestClass($value[0], $value[1], $value[2]));
$storage->offsetSet(new TestClass($value[0], $value[1], $value[2]));
}

var_dump(count($storage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $storage = new MyStorage();

foreach(array(1=>"foo",2=>42) as $key => $value)
{
$storage->attach(new TestClass($key), $value);
$storage->offsetSet(new TestClass($key), $value);
}

var_dump(count($storage));
Expand All @@ -52,8 +52,8 @@ foreach($storage2 as $object)
}

var_dump($storage2);
$storage->attach(new TestClass(3), new stdClass);
$storage->attach(new TestClass(4), new TestClass(5));
$storage->offsetSet(new TestClass(3), new stdClass);
$storage->offsetSet(new TestClass(4), new TestClass(5));
echo "===UNSERIALIZE2===\n";
var_dump(unserialize(serialize($storage)));
$storage->rewind();
Expand All @@ -70,7 +70,7 @@ $storage->next();
$storage->next();
var_dump($storage->key());
var_dump($storage->current());
$storage->attach($storage->current(), "replaced");
$storage->offsetSet($storage->current(), "replaced");
echo "===UNSERIALIZE4===\n";
var_dump(unserialize(serialize($storage)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ $o2 = new StdClass;
$o3 = new StdClass;

$a = new A;
$a->attach($o1);
$a->attach($o2);
$a->offsetSet($o1);
$a->offsetSet($o2);

$b = new SplObjectStorage();
$b->attach($o2);
$b->attach($o3);
$b->offsetSet($o2);
$b->offsetSet($o3);

$a->addAll($b);
$a->offsetUnset($b);

var_dump($a->count());

$a->detach($o3);
$a->offsetUnset($o3);
var_dump($a->count());

$a->removeAll($b);
var_dump($a->count());
?>
--EXPECT--
int(3)
int(2)
int(2)
int(1)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ SPL: SplObjectStorage addAll/removeAll
class Foo {}

$storageA = new \SplObjectStorage();
$storageA->attach(new \Foo);
$storageA->attach(new \Foo);
$storageA->offsetSet(new \Foo);
$storageA->offsetSet(new \Foo);

echo ("Count storage A: " . count($storageA));
foreach ($storageA as $object) {
Expand Down