php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77797 Array assignment
Submitted: 2019-03-26 12:27 UTC Modified: 2019-03-26 12:35 UTC
From: taco at procurios dot nl Assigned:
Status: Duplicate Package: Unknown/Other Function
PHP Version: 7.2.16 OS: linux
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.
Password:
Status:
Package:
Bug Type:
Summary:
From: taco at procurios dot nl
New email:
PHP Version: OS:

 

 [2019-03-26 12:27 UTC] taco at procurios dot nl
Description:
------------
When passing an array append assignment directly to a public or protected method with opcache enabled, the array itself is passed to the method instead of the assigned value. Calling private methods or functions will not trigger this behaviour.

This behaviour only occurs with opcache enabled (tested both in cli and as apache module), so you'll need to run it at least twice to see the faulty behaviour.

Test script:
---------------
<?php
class Foo
{
    public function baz($arg)
    {
        return $arg;
    }

    public function bar()
    {
        $a = [];
        return $this->baz($a[] = 'foo');
    }
}

$foo = new Foo();
var_dump($foo->bar());

Expected result:
----------------
string(3) "foo"

Actual result:
--------------
array(1) {
  [0] =>
  string(3) "foo"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-26 12:35 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2019-03-26 12:35 UTC] nikic@php.net
Duplicate of bug #77691, which has been fixed in 7.2.17.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC