5

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 object from the storage.*/
    public function detach($javaScript){}

    /**Adds all objects-data pairs from a different JavaScriptBundle storage in the current storage.*/
    public function addAll(\SplObjectStorage $storage){}

    /**Removes objects contained in another storage from the current storage.*/
    public function removeAll(\SplObjectStorage $storage){}

    /**Removes all objects except for those contained in another storage from the current storage.*/
    public function removeAllExcept(\SplObjectStorage $storage){}

    /**Alias to JSObjectStorage::attach. */    
    public function offsetSet($javaScript, $data = null){}

    /**Alias to JSObjectStorage::detach*/
    public function offsetUnset($javaScript){}

    /**Returns the data associated with an object in the storage.*/
    public function offsetGet($javaScript){}

    /**This method calculates an identifier for the objects added to JSObjectStorage object.*/
    public function getHash($javaScript){}
}

and this is the SplObjectStorage:

http://php.net/manual/en/class.splobjectstorage.php

As you can see they are identical but when I instantiate JSObjectSTorage, I get the following error:

Strict standards: Declaration of MOWAFW\Core\Type\JavaScript\JSObjectStorage::addAll() should be compatible with that of SplObjectStorage::addAll() in /Users/**/JSObjectStorage.php on line 175

And this happens to removeAll() and removeAllExcept().

Any ideas?!


I'm using:

PHP 5.3.10 with Suhosin-Patch (cli) (built: Feb 20 2012 22:55:53) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans
Tivie
  • 18,864
  • 5
  • 58
  • 77
  • 2
    What version of PHP are you using? Just tried with 5.4.8 and your code works just fine. – Roberto Oct 30 '12 at 02:36
  • 1
    Are you sure this does not happen with the `removeAll()` method also? If it does, then I would suspect type hinting for the parameters might be causing it - maybe an incompatibility with your PHP version, not sure though. – inhan Oct 30 '12 at 22:58
  • @inhan Yes, like I stated in the question this also happens with removeAll() and removeAllExcept(). Removing the type hint does not fix the problem. – Tivie Oct 30 '12 at 23:09
  • I must have missed that, sorry. Then, apparently it's related to type hinting. Looks like [**bug #40653**](http://forge.typo3.org/issues/40653) despite version difference. – inhan Oct 30 '12 at 23:46
  • @inhan Ah! Bloody hell!!! That's some really nasty bug. At least there's a workaround, but even so... Well, thank you very much. Make an answer and the "green tick" is yours. – Tivie Oct 31 '12 at 00:06
  • Sure. Although it's not a solution I'm glad it explains the issue. – inhan Oct 31 '12 at 00:39

1 Answers1

3

Someone posted a bug report entitled "Namespace interfaces not working due to type hinting issues" (Bug #40653), which looks like your case despite the PHP version difference (it reads v. < 5.3.7).

inhan
  • 7,394
  • 2
  • 24
  • 35