php.net |  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
Votes:1
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: public at grik dot net
New email:
PHP Version: OS:

 

 [2016-03-28 14:13 UTC] public at grik dot net
Description:
------------
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) {
    }
}

Collection::fromArray([]);


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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-29 10:22 UTC] krakjoe@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: krakjoe
 [2016-03-29 10:23 UTC] krakjoe@php.net
-Assigned To: krakjoe +Assigned To:
 [2016-03-29 10:28 UTC] krakjoe@php.net
-Status: Verified +Status: Open -Type: Bug +Type: Documentation Problem
 [2016-03-29 10:28 UTC] krakjoe@php.net
The documentation and declarations do not match.
 [2016-03-29 10:29 UTC] krakjoe@php.net
-Summary: wrong error for SplFixedArray +Summary: Incorrect Documentation for SplFixedArray::fromArray
 [2016-03-29 11:08 UTC] dmitry@php.net
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] krakjoe@php.net
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] krakjoe@php.net
Another problem with internal functions, is default values for arguments.

I don't know how to fix it ...
 [2018-06-16 17:13 UTC] cmb@php.net
-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] cmb@php.net
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,
though.

> 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] <https://github.com/php/php-src/blob/f2b4ec4bdc595773fb49b7d6ae8942c61f436288/ext/spl/spl_fixedarray.c#L675>
[2] <https://github.com/php/php-src/blob/f2b4ec4bdc595773fb49b7d6ae8942c61f436288/ext/spl/spl_fixedarray.c#L1045>
[3] <https://github.com/php/php-src/blob/PHP-7.0.0/Zend/zend_API.h#L104-L108>
 [2018-06-16 17:34 UTC] nikic@php.net
@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] nikic@php.net
This should get fixed in PHP 8, as soon as stubs for SplFixedArray are added.
 [2020-06-25 08:04 UTC] nikic@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-06-25 08:04 UTC] nikic@php.net
Fixed in PHP 8.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC