Req #31627 [Opn]: return statement should return

From: Date: Mon, 23 Mar 2015 19:00:19 +0000
Subject: Req #31627 [Opn]: return statement should return
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191551@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 Updated by: cmb@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: Then again, what's wrong with if (!mysql_connect(blah)) return false; instead? Previous Comments: ------------------------------------------------------------------------ [2015-01-08 23:23:44] ajf@php.net This would make sense, I don't see why we couldn't make "return" an expression. ------------------------------------------------------------------------ [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

« previous php.bugs (#191551) next »