Req #31627 [Com]: return statement should return

From: Date: Thu, 08 Jan 2015 23:23:45 +0000
Subject: Req #31627 [Com]: return statement should return
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189778@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=31627&edit=1

 ID:                 31627
 Comment by:         ajf@php.net
 Reported by:        mnemo at minimum dot se
 Summary:            return statement should return
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        *
 Block user comment: N
 Private report:     N

 New Comment:

This would make sense, I don't see why we couldn't make "return" an expression.


Previous Comments:
------------------------------------------------------------------------
[2014-03-12 08:40:37] 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.

------------------------------------------------------------------------
[2011-07-20 23:36:12] 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;

------------------------------------------------------------------------
[2005-01-20 19:28:40] 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.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=31627&edit=1


Thread (6 messages)

« previous php.bugs (#189778) next »