|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-07-12 18:51 UTC] xxalfa at gmail dot com
Description:
------------
I want to "OR" like to use otherwise. I like the program structure with "GOTO" and "THROW". Is this sensible?
Test script:
---------------
<?php
//-------------------------------------------------
// TEST "OR"
//-------------------------------------------------
$test = true;
//-------------------------------------------------
// EXIT
//-------------------------------------------------
// $test == true or exit;
// echo 'TEST TRUE';
//-------------------------------------------------
// DIE
//-------------------------------------------------
// $test == true or die ( 'TEST END' );
// echo 'TEST TRUE';
//-------------------------------------------------
// GOTO
//-------------------------------------------------
// Parse error: syntax error, unexpected 'goto' (T_GOTO) in /xamppfiles/htdocs/1.php on line 32
// $test == true or goto TEST_END;
// echo 'TEST TRUE';
// TEST_END:
// echo 'TEST END';
//-------------------------------------------------
// THROW
//-------------------------------------------------
// Parse error: syntax error, unexpected 'throw' (T_THROW) in /xamppfiles/htdocs/1.php on line 42
// try
// {
// $test == true or throw new Exception( 'TEST ERROR', 1 );
// echo 'TEST TRUE';
// }
// catch ( Exception $exception )
// {
// echo $exception->getMessage();
// }
//-------------------------------------------------
// Apache Version
//-------------------------------------------------
// Apache/2.4.18 (Unix) OpenSSL/1.0.2h PHP/7.0.8 mod_perl/2.0.8-dev Perl/v5.16.3
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 07:00:01 2025 UTC |
@kalle: There's not really a technical problem here, just needs a change in grammar and dummy return value. This will need an RFC though. I'm personally not a fan of this, because I consider it bad style. Also consider what specifically you want to allow. Do you want to special-case the "or" operator (bad idea imho) or do we end up allowing "1 + throw $x" (consistent, but meh)? Also consider the precedence of these new "operators". What does "true or return 1 or return 2" do? Is it "true or (return 1) or (return 2)" or is it "true or (return (1 or (return 2)))? Lastly, consider which statements you want to convert to expressions. All "jump" operations, i.e. throw, return, break, continue, goto? Or more than that? Do you want to allow "true or unset($var)"? Do you want to allow "true or foreach ($x as $y) { ... }"? Etc.