php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55222 Fatal Error disappears when using paranthesis
Submitted: 2011-07-17 16:51 UTC Modified: 2016-02-14 21:56 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: hanskrentel at yahoo dot de Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.6 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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hanskrentel at yahoo dot de
New email:
PHP Version: OS:

 

 [2011-07-17 16:51 UTC] hanskrentel at yahoo dot de
Description:
------------
PHP 5.3 is giving me nice, sound FATAL ERRORS when using functions like reset() within a variable. However it looks like that it's not always taken care of that consequentially.

I don't even get a strict standards warning even.

Test script:
---------------
<?php
error_reporting(~0);

function get_array() {
   return Array(1);
}

function foo() {
   // return reset( (get_array()?:null) );
   //               ^Fatal error: Only variables can be passed by reference
   return reset( (get_array()) ); 
  //             ^Only? This one works OK
}

foo();


Expected result:
----------------
Fatat error.

Actual result:
--------------
All fine.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-17 16:52 UTC] hanskrentel at yahoo dot de
within = without in the description.
 [2011-07-18 22:21 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2011-07-18 22:21 UTC] aharvey@php.net
reset() requires a variable that can be passed by reference. There's really no way 
to get around that, hence the fatal error.
 [2011-07-19 08:10 UTC] hanskrentel at yahoo dot de
Actually I'm concerned that

    reset( (get_array()) );

does _not_ give a fatal error. This contradicts the last comment "There's really 
no way to get around that [getting a fatal error]".

Why does it not give a fatal error? There is no variable.
 [2011-07-27 16:34 UTC] hanskrentel at yahoo dot de
I can only remind again that the first comment from php.net obviously misread this report.

I am _missing_ the fatal error.
 [2011-07-27 16:51 UTC] arpad@php.net
-Status: Bogus +Status: Verified
 [2011-08-24 08:56 UTC] hanskrentel at yahoo dot de
I assume you want to say that the linked answer explicitly explains the problem.

Should we make use of this feature when programming PHP or not?
 [2011-09-12 07:21 UTC] tom at kera dot name
cataphract, this bug report came out of that Stack Overflow post. I don't think that the Stack Overflow post resolves it in any useful way.
 [2014-03-17 21:38 UTC] nikic@php.net
@hanskretel: No, you should not. As this is a bug, the behavior might change in a future PHP version without further notice.
 [2016-02-14 21:56 UTC] nikic@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nikic
 [2016-02-14 21:56 UTC] nikic@php.net
In PHP 7 this consistently throws a notice, the parenthesis no longer make a difference.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Sep 08 09:00:01 2025 UTC