php.net |  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
Votes:2
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
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: mnemo at minimum dot se
New email:
PHP Version: OS:

 

 [2005-01-20 19:28 UTC] mnemo at minimum dot se
Description:
------------
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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-02 02:11 UTC] jani@php.net
-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] ajf@php.net
This would make sense, I don't see why we couldn't make "return" an expression.
 [2015-03-23 19:00 UTC] cmb@php.net
Then again, what's wrong with

  if (!mysql_connect(blah)) return false;
  
instead?
 [2017-10-26 11:27 UTC] jhdxr@php.net
-Status: Open +Status: Suspended
 [2017-10-26 11:27 UTC] jhdxr@php.net
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 (internals@lists.php.net) as an RFC. Please read the guide about creating RFCs here:
https://wiki.php.net/rfc/howto
If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list (http://php.net/mailing-lists.php) 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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 16:01:30 2024 UTC