Bug #76187 [Opn->Nab]: Assigning new object in ref-parameter: fn($obj = new stdClass()) raises notice
| From: | requinix@php.net | Date: | Thu, 05 Apr 2018 15:01:06 +0000 |
| Subject: | Bug #76187 [Opn->Nab]: Assigning new object in ref-parameter: fn($obj = new stdClass()) raises notice | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-214622@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76187&edit=1
ID: 76187
Updated by: requinix@php.net
Reported by: matthes at leuffen dot de
Summary: Assigning new object in ref-parameter: fn($obj = new
stdClass()) raises notice
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
PHP Version: 7.2.4
Block user comment: N
Private report: N
New Comment:
$obj=new stdClass() is an expression and expressions cannot be passed by reference.
Previous Comments:
------------------------------------------------------------------------
[2018-04-05 14:58:30] matthes at leuffen dot de
Description:
------------
Notice is falsely triggered. The two examples should be the same.
Test script:
---------------
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
// Function with reference parameter
function fn (&$obj) {}
fn($obj = new stdClass()); // <- Triggers notice: Only variables should be passed by reference
// ... should be the same as ...
$obj = new stdClass();
fn($obj); // <- No warning
Expected result:
----------------
No notice
Actual result:
--------------
Notice: Only variables should be passed by reference in xxx
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76187&edit=1