php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #68584 I hope "unset" keyword can be used after "or"
Submitted: 2014-12-10 07:10 UTC Modified: 2017-08-05 04:54 UTC
From: 523826219 at qq dot com Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: Irrelevant OS: Windows&&Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: 523826219 at qq dot com
New email:
PHP Version: OS:

 

 [2014-12-10 07:10 UTC] 523826219 at qq dot com
Description:
------------
<?php
 $myDS=array(1,2,3);
 false===($targetKey=array_search(3,$myDS)) or var_dump($targetKey);  
 // outputs:2

 false===($targetKey=array_search(3,$myDS)) or unset($myDS[$targetKey]);   
 //  Fail:this is a syntax error!(Actually I just want to remove the target element with specified value from the array-$myDS,but it does not work!)



Test script:
---------------
<?php
 $myDS=array(1,2,3);
 false===($targetKey=array_search(3,$myDS)) or var_dump($targetKey);  
 // outputs:2

 false===($targetKey=array_search(3,$myDS)) or unset($myDS[$targetKey]);   
 //  Fail:this is a syntax error!(Actually I just want to remove the target element with specified value from the array-$myDS,but it does not work!)

 =>So ,I hope "unset" keyword  can be used after "or" keyword,Thank you !

Expected result:
----------------
Actually "exit" keyword can be used after "or" keyword,why not "unset"?
for example:
!defined('IN_MANAGE') or exit('no access for this site!'); // works successfully

I hope "unset" keyword  can be used after "or" keyword,Thank you !
for example:
!isset($somekey) or unset($myDS[$somekey]);

Actual result:
--------------
Actually "exit" keyword can be used after "or" keyword,why not "unset"?
for example:
!defined('IN_MANAGE') or exit('no access for this site!'); // works successfully

I hope "unset" keyword  can be used after "or" keyword,Thank you !
for example:
!isset($somekey) or unset($myDS[$somekey]);

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-10 08:24 UTC] chx@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2014-12-10 08:24 UTC] chx@php.net
The specification describes the current behavior and this is a feature request against I guess PHP 7.
 [2015-06-08 19:54 UTC] cmb@php.net
The `unset` language construct is actually a statement (what
should be explicitly documented). Therefore `unset` can't be used
where an expression is expected. It might be reasonable to change
this, but then again, you can simply change your code:

  if (false!==($targetKey=array_search(3,$myDS))) unset($myDS[$targetKey]);
 [2017-08-05 04:54 UTC] stas@php.net
-Status: Open +Status: Suspended
 [2017-08-05 04:54 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: Wed Apr 24 19:01:31 2024 UTC