|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61529 Make unset() an expression
Submitted: 2012-03-27 13:45 UTC Modified: 2013-02-18 00:35 UTC
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: asserte at gmail dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.4.1RC/5.5.0-dev OS: Linux
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:
Solve the problem:
30 - 25 = ?
Subscribe to this entry?

 [2012-03-27 13:45 UTC] asserte at gmail dot com
isset() && unset()

PHP Parse error:  syntax error, unexpected 'unset' (T_UNSET), expecting ')' in 
/tmp/isset.php on line 4

Tested on PHP 5.4.0-3 (cli) (built: Mar 22 2012 07:59:57) 

Test script:
$> cat /tmp/isset.php
  1 <?php
  3     $entity = array('id' => 1, 'name' => 'example');
  4     isset( $entity['id'] ) && unset( $entity['id'] );

$> php /tmp/isset.php
PHP Parse error:  syntax error, unexpected 'unset' (T_UNSET), expecting ')' in /tmp/isset.php on line 3

Expected result:
unset should works.


bug61529.phpt (last revision 2012-03-29 12:51 UTC by
bug61529.patch (last revision 2012-03-29 12:49 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-27 13:49 UTC] asserte at gmail dot com
-Package: *Compile Issues +Package: Scripting Engine problem
 [2012-03-27 13:49 UTC] asserte at gmail dot com
Move to SE problems
 [2012-03-28 08:51 UTC]

$ php -r '1 && unset($var["a"]);'

is enough.

[yohgaki@dev php-src]$ ./sapi/cli/php -v
PHP 5.5.0-dev (cli) (built: Mar 28 2012 17:33:51) (DEBUG)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

[yohgaki@dev php-src]$ ./sapi/cli/php -r 'unset($var["a"]);'
[yohgaki@dev php-src]$ ./sapi/cli/php -r '1 && unset($var["a"]);'

Parse error: syntax error, unexpected 'unset' (T_UNSET) in Command line code on 
line 1
 [2012-03-28 08:51 UTC]
-Status: Open +Status: Verified
 [2012-03-28 08:52 UTC]
-Operating System: Debian +Operating System: Linux -PHP Version: 5.4.0 +PHP Version: 5.4.1RC/5.5.0-dev
 [2012-03-29 12:49 UTC]
The following patch has been added/updated:

Patch Name: bug61529.patch
Revision:   1333025364
 [2012-03-29 12:49 UTC]
-Assigned To: +Assigned To: dmitry
 [2012-03-29 12:49 UTC]
Dmitry, could you review my patch for this bug plz?  thanks
 [2012-03-29 12:51 UTC]
The following patch has been added/updated:

Patch Name: bug61529.phpt
Revision:   1333025478
 [2012-03-29 12:53 UTC]
oh, the patch is based on trunk.
 [2012-03-29 13:07 UTC] reeze dot xia at gmail dot com
unset() is like echo These are language constuct, Both of them are not 
expression in PHP, so code like this:

$c = 1 && echo 3;

IS NOT VALID script too;

Those language construct are "unticked_statement" @see 
if,switch, do while and etc they all.

So from now on, This is not a bug.

Maybe we could make unset() a normal expression. I don't know how this decision 
made, maybe we can discuss it in maillist.
 [2012-03-29 13:28 UTC]
unset() is a statement, not an expression. So you obviously can't use it in an expression context. Changing buy type to Feature Request.

In my eyes the behavior *should not* be changed. unset() does not have a meaningful return value and as such should not be allowed in an expression context.
 [2012-03-29 13:28 UTC]
-Summary: Parsing error +Summary: Make unset() an expression -Type: Bug +Type: Feature/Change Request
 [2012-03-29 14:59 UTC]
@nikic thinking of isset, include. :)
 [2012-03-29 14:59 UTC]
@nikic thinking of isset, include. :)
 [2012-03-29 15:02 UTC]
-Summary: Make unset() an expression +Summary: Parsing error while use unset with boolean and -Type: Feature/Change Request +Type: Bug
 [2012-03-29 15:34 UTC]
@nikic @reeze, after a deep thought,  I realize that I was wrong. yes, to fix this 
we should make unset return something.. 

so, mark it as a req , 
 [2012-03-29 15:36 UTC]
-Summary: Parsing error while use unset with boolean and +Summary: Make unset() an expression -Type: Bug +Type: Feature/Change Request -Assigned To: dmitry +Assigned To:
 [2012-03-30 12:12 UTC]
-Status: Verified +Status: Feedback
 [2012-03-30 12:12 UTC]
I didn't test the patch just made a quick review. I suppose it's incomplete. With patch it's possible to write $a = unset($b), but UNSET opcode doesn't care about return value, so what's going to be assigned to $a?

In any case, I think, such changes are not allowed in minor releases. So must not be committed into 5.4. Personally, I don't think it makes sense for trunk as well. It always possible to write

if (isset($entity['id'])) unset($entity['id']);

More clear, and just a few characters more :)
 [2012-05-09 15:00 UTC] jelle dot zijlstra at gmail dot com
I just hit this bug trying to unset a variable in a for loop, like this:
for( ; ; unset($i)) {
    if($someCondition) {
        $i = 42;
    if(isset($i)) {
    } else {

I understand why this currently fails and obviously there are workarounds, but intuitively unset should work in the third expression of a for loop.
 [2013-02-18 00:35 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 23:01:29 2024 UTC