Req #60305 [Com]: myClass::unset() keyword conflict

From: Date: Mon, 21 Nov 2011 03:50:41 +0000
Subject: Req #60305 [Com]: myClass::unset() keyword conflict
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-165392@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60305&edit=1

 ID:                 60305
 Comment by:         anon at anon dot anon
 Reported by:        matty023 at gmail dot com
 Summary:            myClass::unset() keyword conflict
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 PHP Version:        5.4.0RC1
 Block user comment: N
 Private report:     N

 New Comment:

@francois: It's not a bug. It's a feature.

It's kind of accepted that all programming languages have some keywords you can't use as
identifier names. The general solution is to just choose a synonym. Possible alternative verbs for
"unset" include:
- clear
- remove
- delete
- dispose
- drop
- erase

Unusually, the language limitation is actually fixable for "unset" because of its obvious
function-like syntax. It's probably not a priority though. Also, at best, it would break the
history of PHP syntax-coloring editors turning "unset" keyword color.


Previous Comments:
------------------------------------------------------------------------
[2011-11-15 19:32:03] francois dot dambrine at isen-lille dot fr

This bug also happen in php 5.3.6 (ubuntu 11.10 default version).

------------------------------------------------------------------------
[2011-11-15 02:19:37] matty023 at gmail dot com

Description:
------------
While "keywords" and "language constructs" cannot be used as function names, I
find myself with the need to have a function in my class named "unset", I also see that
list is a very common and useful term.

After the introduction of classes and namespaces it's time to look at enabling usage of these
common terms in classes and namespaces.



Test script:
---------------
<?php
namespace whatever;
class unsetTest{
	function unset($whatever){
		
	}
}

Expected result:
----------------
Happiness

Actual result:
--------------
//Parse error: syntax error, unexpected 'unset' (T_UNSET), expecting identifier (T_STRING)
in E:\_www\x.php on line #


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60305&edit=1


Thread (4 messages)

« previous php.bugs (#165392) next »