[PHP-DEV] PROPOSAL: unless control structure
My apologies if this has been brought up before, but I searched the archives and couldn't find a reference to it. I'm sure this is the sort of thing that would have already been implemented if there was any desire for it among the developers, but I was wondering if anyone had considered adding support for an unless control structure, similar to the one Perl has. I personally find it much more logical in certain cases. For example, compare this: if (!$user-isAdministrator) { header('Location: ...'); exit; } With this: unless ($user-isAdministrator) { header('Location: ...'); exit; } I think the second one is much easier to read. I strive to write code that is self-documenting, so I tend to pick variable names and function names that are pretty self explanatory. I think an unless control structure would go a long way to helping people write self-documenting code. Just a thought, sorry if this is not the proper forum for this sort of thing. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] PROPOSAL: unless control structure
On Sun, Jan 12, 2003 at 12:53:12PM -0600, Michael Sims wrote: My apologies if this has been brought up before, but I searched the archives and couldn't find a reference to it. I'm sure this is the sort of thing that would have already been implemented if there was any desire for it among the developers, but I was wondering if anyone had considered adding support for an unless control structure, similar to the one Perl has. I personally find it much more logical in certain cases. While it would no doubt be easy to implement, I would consider it unnecessary syntactic sugar. Besides, it actually ends up using _more_ characters (unless(:7, if(!:4) in the long run. -- Jon Parise ([EMAIL PROTECTED]) :: The PHP Project (http://www.php.net/) -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] PROPOSAL: 'unless' control structure
On Sun, 2003-01-12 at 20:47, Sara Golemon wrote: [...] This has been discussed (recently in fact) and won't be done. However, you *can* give your code the type of readability you're looking for with: ($condition) || { /* This will only run if $condition evals to false */ } Nope, that gives me a parse error: thekid@friebes:~ echo '? function unless($c) { return $c; } $c= FALSE; unless($c) || print(!condition\n); ?' | php -q !condition thekid@friebes:~ echo '? function unless($c) { return $c; } $c= FALSE; unless($c) || { print(!condition\n); } ?' | php -q Parse error: parse error in - on line 1 It'll work for exactly one statement (e.g. mysql_connect() or die()), but not with blocks (mysql_connect() or { mail(...); die(); })). -- Timm Friebe [EMAIL PROTECTED] -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php