php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50515 return() in short-circuit / lazy evaluation
Submitted: 2009-12-18 10:26 UTC Modified: 2009-12-18 11:20 UTC
From: ntpt at seznam dot cz Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.12 OS: linux
Private report: No CVE-ID: None
 [2009-12-18 10:26 UTC] ntpt at seznam dot cz
Description:
------------
please allow return() in lazy evaluation /short-circuit syntax like

$result=do_something($blah) or die('nothing done'); // this works

but

$result=do_something($blah) or return(false) ; // does NOT work

I thing it is prety legitimate not only to call die() if do_something() return false, but in this case return() from function or include() as well. I thing it is more cleaner and readable then bunch of

$result=do_something($blah)
if ($result==false){
return false;}
// use you result here

Maybe even codeblock after "or" is worth of considerations

$result=do_something($blah) or { // codeblock, do what you want here 
}
 
 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-18 11:20 UTC] jani@php.net
Never happens.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 22:01:27 2024 UTC