Bug #70606 [Wfx]: The documented signature for SplObjectStorage methods is wrong
| From: | stof at notk dot org | Date: | Wed, 30 Sep 2015 15:57:32 +0000 |
| Subject: | Bug #70606 [Wfx]: The documented signature for SplObjectStorage methods is wrong | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12794@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70606&edit=1
ID: 70606
User updated by: stof at notk dot org
Reported by: stof at notk dot org
Summary: The documented signature for SplObjectStorage
methods is wrong
Status: Wont fix
Type: Bug
Package: Documentation problem
Operating System: n/a
PHP Version: 5.6.13
Block user comment: N
Private report: N
New Comment:
Then why not at least adding a note saying that it is not a true typehint, to avoid WTF for people
actually overwriting the method ?
For 5.x at least, it cannot be anything else than a documentation bug (unless you want to drop all
PHP policies about backward compatibility, which would be a very bad news for the community).
Previous Comments:
------------------------------------------------------------------------
[2015-09-30 15:52:05] salathe@php.net
Okay, if you want to keep it as a documentation bug then I'll close as "won't
fix".
We tell white lies throughout the documentation where it makes more sense than the fine details of
the source, and in this case I think it adds more value to the documentation to have the type
declaration in the prototype than not.
------------------------------------------------------------------------
[2015-09-30 14:21:15] stof at notk dot org
Well, changing the source code would be a BC break, so it cannot be done in 5.x (and it would make
it painful to write such code compatible with both 5.x and 7.x if it gets changed in 7.x btw).
------------------------------------------------------------------------
[2015-09-30 11:51:22] salathe@php.net
This is more a failing of the source code, which doesn't declare the argument type. I'd
rather see this fixed there, than change the documentation.
Would you be okay with changing this to a bug report for the SPL?
------------------------------------------------------------------------
[2015-09-30 10:16:07] stof at notk dot org
Description:
------------
The documentation for the addAll, removeAll and removeAllExcept methods of the SplObjectStorage
shows that the argument is typehinted as SplObjectStorage: http://php.net/manual/en/splobjectstorage.addall.php
While this is true that they accept only SplObjectStorage instances, the methods are NOT typehinted,
which cause issues when trying to overwrite them. We receive an error saying that the signature does
not match, while we follow the documentation.
I had to go read the C source code to understand the actual issue (and I think many people would not
do it).
https://github.com/php/php-src/blob/PHP-5.6/ext/spl/spl_observer.c#L972
https://github.com/php/php-src/blob/PHP-5.6/ext/spl/spl_observer.c#L940
Test script:
---------------
<?php
class MyObjectStorage extends SplObjectStorage
{
public function addAll(SplObjectStorage $object) {}
}
Actual result:
--------------
T
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70606&edit=1