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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC