Questions tagged [splobjectstorage]

13 questions
13
votes
1 answer

What is the difference between SplObjectStorage::contains and SplObjectStorage::offsetExists?

The PHP documentation is not very explicit and only states that: SplObjectStorage::offsetExists Checks whether an object exists in the storage. (PHP >= 5.3.0) SplObjectStorage::contains Checks if the storage contains the object provided. (PHP >=…
Tivie
  • 18,864
  • 5
  • 58
  • 77
7
votes
1 answer

looking up data in splobjectstorage

Greetings people of stackoverflow, for the last days I have been looking at websockets and a PHP library called Ratchet (which is ideal for writing websockets server applications in PHP). In the Ratchet official docs they recommend using…
Binni
  • 73
  • 3
6
votes
1 answer

Using SplObjectStorage as a data map, can you use a mutable array as the data?

In the following code: $storage = new \SplObjectStorage(); $fooA = new \StdClass(); $fooB = new \StdClass(); $storage[$fooA] = 1; $storage[$fooB] = array(); $storage[$fooA] = 2; $storage[$fooB][] = 'test'; I would expect $storage[$fooA] to be 1,…
Joe Lencioni
  • 10,231
  • 18
  • 55
  • 66
5
votes
3 answers

UnexpectedValueException in session_start() php failing SPLObjectStorage serialization

Why UnexpectedValueException is thrown in session_start()? I have object which has property of SPLObjectstorage. That object is assigned to session like $_SESSION['foo'] = $barObject; I suspect that internal session serializing facing problem to…
varuog
  • 3,031
  • 5
  • 28
  • 56
5
votes
1 answer

Method declaration is compatible but PHP complains

So I have this class: class JSObjectStorage extends \SplObjectStorage { /**Adds a JavaScript object inside the storage, and optionally associate it to some data.*/ public function attach($javaScript, $data = null){} /**Removes the…
Tivie
  • 18,864
  • 5
  • 58
  • 77
3
votes
1 answer

PHP SplObjectStorage attach and push to top of the list

I have a little situation, I am using the SplObjectStorage object and at some point I need to attach an item but also push it to the top of the list so when I iterate through the items I will get it as first…
ptheofan
  • 2,150
  • 3
  • 23
  • 36
2
votes
1 answer

Symfony 3 - Form - CollectionType in Entity without Doctrine

I'm struggling with symfony3 forms and the CollectionType class: I have a page with several complex forms. I do not use any database (the validated forms are sent to a foreign REST-service) Now let's say I have an entity object for my request called…
j0nnybrav0
  • 123
  • 2
  • 11
1
vote
1 answer

Custom iteration for SplObjectStorage

I want to modify the way to iterate an SPLObjectStorage object, such as sorting it first by the data (info). So, in a loop, it goes numerically from a to z (using sort() function) But, in SPLObjectStorage, there is no access to the array, right ? Is…
Terry Djony
  • 1,975
  • 4
  • 23
  • 41
0
votes
1 answer

Multiple dimensional map using objects as keys

I have a set of objects (MainObject) which are uniquely defined by two objects (SubObject1, SubObject2) and a string (theString). I with to retrieve a MainObject from the set by returning an existing object based on the two subobjects and string…
user1032531
  • 24,767
  • 68
  • 217
  • 387
0
votes
1 answer

What happens if the same object instance is attached multiple times to SplObjectStorage?

Or in other words, should I bother checking whether it already is in the set before attaching it? $s = new SplObjectStorage(); foreach($arrayOfObjects as $primaryObject) { $subObject=$primaryObject->getSubObject(); //It is possible that a…
user1032531
  • 24,767
  • 68
  • 217
  • 387
0
votes
1 answer

PHP SplObjectStorage Cannot create within a class

Would it be possible to initialize a protected SplObjectStorage as a map within a class? I seem to be running into an error whenever I try this. Similar to example below: class a { protected $a = new SplObjectStorage(); ... }
snehoozle
  • 273
  • 2
  • 4
  • 14
0
votes
1 answer

SplObjectStorage only maps by instances

My problem is I want to map by object equality (==), not unique instances. In other words, refactor this to not throw an error and return the mapped value: $var1 = (object) [1,2,10]; $var2 = (object) [1,2,10]; $objmap = new…
Hamster
  • 2,962
  • 7
  • 27
  • 38
-1
votes
1 answer

How to push large set of strings to SplObjectStorage in PHP and if string exist not to push

Basically what I need is to push a large set of strings to SplObjectStorage and if each string doesn't exist do some kind of action, if it does exist do other action. $o1->id = '11111'; $s->attach($o1); $o1->id = '22222'; $s->attach($o1); I only…
user3410843
  • 195
  • 3
  • 18