php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80822 signature of ArrayObject::exchangeArray($array) has changed
Submitted: 2021-03-03 00:20 UTC Modified: 2021-11-11 14:26 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: ievgen dot varava at spryker dot com Assigned:
Status: Open Package: SPL related
PHP Version: 8.0.2 OS: OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
33 + 45 = ?
Subscribe to this entry?

 
 [2021-03-03 00:20 UTC] ievgen dot varava at spryker dot com
Description:
------------
---
From manual page: https://php.net/arrayobject.exchangearray
---
Signature of ArrayObject::exchangeArray($array) has changed, but is not documented. Some code that worked in php7 might become incompatible with php8

Test script:
---------------
<?php
interface intA {
    public function exchangeArray($param);
}

class classB extends ArrayObject implements intA {}
?>

Expected result:
----------------
no errors (works in php 7.4.13)

Actual result:
--------------
Fatal error:  Declaration of ArrayObject::exchangeArray(object|array $array) must be compatible with intA::exchangeArray($param)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-03 00:37 UTC] ievgen dot varava at spryker dot com
Also, passing invalid parameter throws TypeError in PHP8 vs InvalidArgumentException in PHP7

<?php
$a = new ArrayObject();
$a->exchangeArray(123);
?>
 [2021-11-11 14:26 UTC] cmb@php.net
-Package: Documentation problem +Package: SPL related
 [2021-11-11 14:26 UTC] cmb@php.net
> Signature of ArrayObject::exchangeArray($array) has changed, but
> is not documented.

That's a bit tricky.  The method always expected array|object (and
the documentation reflects that now), but prior to PHP 8.0.0, the
arginfo (which is relevant for inheritance) had no info about the
parameter type.  This likely affects a lot of other methods as
well.

> Also, passing invalid parameter throws TypeError in PHP8 vs
> InvalidArgumentException in PHP7

Passing invalid parameter types to internal functions is
documented to be undefined behavior[1], so we may not want to
document this change.

[1] <https://www.php.net/manual/en/functions.internal.php>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC