php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72589 "OR" is used differently
Submitted: 2016-07-12 18:51 UTC Modified: 2017-08-04 22:59 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: xxalfa at gmail dot com Assigned:
Status: Suspended Package: *General Issues
PHP Version: 7.0.8 OS: macOS 10.11.5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
23 - 4 = ?
Subscribe to this entry?

 
 [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 

?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-13 01:23 UTC] kalle@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2016-07-13 01:23 UTC] kalle@php.net
I've personally wished for this for a long time, especially the or throw part.

Assigning it to you Nikita for some input, can this be implemented in a sensible manner with ZE?
 [2016-07-13 10:19 UTC] cmb@php.net
Related to request #31627.
 [2016-07-13 10:41 UTC] nikic@php.net
-Status: Assigned +Status: Open -Assigned To: nikic +Assigned To:
 [2016-07-13 10:41 UTC] nikic@php.net
@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.
 [2016-07-13 11:03 UTC] cmb@php.net
And all that so one could write

  $test or exit;

instead of

  if ($test) exit;

Doesn't make sense to me.
 [2016-07-13 11:05 UTC] cmb@php.net
Should have been

  if (!$test) exit;
 [2016-07-13 17:06 UTC] xxalfa at gmail dot com
@nikic I thank you for your detailed thoughts.

@cmb recognizes it well, you need a negation.
 [2016-07-13 17:14 UTC] cmb@php.net
> @cmb recognizes it well, you need a negation.

Then we might as well introduce `unless`, see
<http://docstore.mik.ua/orelly/perl4/prog/ch04_03.htm>.
 [2017-08-04 22:59 UTC] stas@php.net
-Status: Open +Status: Suspended
 [2017-08-04 22:59 UTC] stas@php.net
Thank you for your interest in PHP and for submitting a feature request. Please be aware that due to the magnitude of change this request requires, it would be necessary to discuss it on PHP Internals list (internals@lists.php.net) as an RFC. Please read the guide about creating RFCs here:
https://wiki.php.net/rfc/howto
If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list (http://php.net/mailing-lists.php) and/or solicit help from one of the experienced developers. 

Please to not consider this comment as a negative view on the merits of your proposal - every proposal which requires changes of certain magnitude, even the very successful and widely supported ones, must be done through the RFC process. This helps make the process predictable, transparent and accessible to all developers.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC