|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #31627 return statement should return
Submitted: 2005-01-20 19:28 UTC Modified: 2017-10-26 11:27 UTC
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mnemo at minimum dot se Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-01-20 19:28 UTC] mnemo at minimum dot se
I wish "return doh" was treated like an expression when though this expression will never be computable.

The reason is that I want to write this:

mysql_connect(blah) or return false;

Just like I do with die etc.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-02 02:11 UTC]
-Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: All +Operating System: * -PHP Version: Irrelevant +PHP Version: *
 [2011-07-20 23:36 UTC] binarycleric at gmail dot com
That really isn't what return does because it's not a conditional.  Similar 
behaviour can be achieved by using: 

return (mysql_connect($blah) !== false) ? true : false;
 [2014-03-12 08:40 UTC] asphp at dsgml dot com
binarycleric - that doesn't do the same thing in the slightest.

That would cause the return to run either way. What mnemo wants is for the return to happen ONLY if mysql fails.

Otherwise it should continue to the next line.

This works:

function foo() {}

mysql_connect(blah) or foo(false);

But this doesn't:

mysql_connect(blah) or return(false);

And I think it should.
 [2015-01-08 23:23 UTC]
This would make sense, I don't see why we couldn't make "return" an expression.
 [2015-03-23 19:00 UTC]
Then again, what's wrong with

  if (!mysql_connect(blah)) return false;
 [2017-10-26 11:27 UTC]
-Status: Open +Status: Suspended
 [2017-10-26 11:27 UTC]
Thank you for your interest in PHP and for submitting a feature request. Please be aware that due to the magnitude of change this request requires, it would be necessary to discuss it on PHP Internals list ( as an RFC. Please read the guide about creating RFCs here:
If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list ( and/or solicit help from one of the experienced developers. 

Please to not consider this comment as a negative view on the merits of your proposal - every proposal which requires changes of certain magnitude, even the very successful and widely supported ones, must be done through the RFC process. This helps make the process predictable, transparent and accessible to all developers.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 18 02:03:34 2021 UTC