|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71909 wrong error for SplFixedArray
Submitted: 2016-03-28 14:13 UTC Modified: 2020-06-25 08:04 UTC
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: public at grik dot net Assigned: nikic (profile)
Status: Closed Package: SPL related
PHP Version: 7.0.4 OS: MacOS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: public at grik dot net
New email:
PHP Version: OS:


 [2016-03-28 14:13 UTC] public at grik dot net
When extending the SplFixedArray overriding fromArray() method, PHP shows incorrect error text.

The correct interface of a fromArray method is
   public static function fromArray($array, $save_indexes = true)
without array typehint.

Test script:
class Collection extends \SplFixedArray
    public static function fromArray(array $array, $save_indexes = true) {


Expected result:
no error

Actual result:
Warning: Declaration of Collection::fromArray(array $array, $save_indexes = true) should be compatible with SplFixedArray::fromArray($data, $save_indexes = NULL) in test.php on line 12


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-29 10:22 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: krakjoe
 [2016-03-29 10:23 UTC]
-Assigned To: krakjoe +Assigned To:
 [2016-03-29 10:28 UTC]
-Status: Verified +Status: Open -Type: Bug +Type: Documentation Problem
 [2016-03-29 10:28 UTC]
The documentation and declarations do not match.
 [2016-03-29 10:29 UTC]
-Summary: wrong error for SplFixedArray +Summary: Incorrect Documentation for SplFixedArray::fromArray
 [2016-03-29 11:08 UTC]
I'm not sure if this is a documentation problem for this function.
It's an inconsistent documentation for most internal functions.

Especially in this case, we expect "array" as first argument, but we don't have "array" type hint.
 [2016-03-29 12:59 UTC]
Agree, it's a general problem with internal functions, and their documentation.

I don't see that it can be solved by changing the arginfo though, that would surely break too much code, wouldn't it ?

The only thing we can do in this, and similar cases, is update the documentation to reflect the truth about the prototype, I think.
 [2016-03-29 13:07 UTC]
Another problem with internal functions, is default values for arguments.

I don't know how to fix it ...
 [2018-06-16 17:13 UTC]
-Summary: Incorrect Documentation for SplFixedArray::fromArray +Summary: wrong error for SplFixedArray -Status: Open +Status: Verified -Type: Documentation Problem +Type: Bug
 [2018-06-16 17:13 UTC]
This is not really a documentation issue, since
SplFixedArray::fromArray() indeed expects an array as first
argument[1].  The actual problem is that the arginfo is not yet
specific enough to reflect this[2].  As of PHP 7.0.0 a more
elaborate API is available[3], but it has been missed to apply it,
and for BC reasons we can't fix this for *methods* in a minor
release, so it'll have to wait for PHP 8.  In my opinion, it would
be okay to improve the arginfo for *functions* for PHP 7.3,

> Another problem with internal functions, is default values for
> arguments.

It seems to me that we should be able to add this information to
the arginfo.

[1] <>
[2] <>
[3] <>
 [2018-06-16 17:34 UTC]
@cmb: I believe since PHP 7.2 we can add type hints, as they may now be dropped in child classes.

However we should not start doing this across the board until such a time as types are no longer checked for internal functions. Otherwise we'll be duplicating type-checks that zpp already performs.
 [2019-12-06 14:55 UTC]
This should get fixed in PHP 8, as soon as stubs for SplFixedArray are added.
 [2020-06-25 08:04 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-06-25 08:04 UTC]
Fixed in PHP 8.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 12:01:31 2024 UTC