php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60305 myClass::unset() keyword conflict
Submitted: 2011-11-15 02:19 UTC Modified: 2012-04-03 01:43 UTC
Votes:7
Avg. Score:3.9 ± 1.6
Reproduced:7 of 7 (100.0%)
Same Version:3 (42.9%)
Same OS:4 (57.1%)
From: matty023 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.4.0RC1 OS:
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: matty023 at gmail dot com
New email:
PHP Version: OS:

 

 [2011-11-15 02:19 UTC] 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 #

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-15 19:32 UTC] francois dot dambrine at isen-lille dot fr
This bug also happen in php 5.3.6 (ubuntu 11.10 default version).
 [2011-11-21 03:50 UTC] anon at anon dot anon
@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.
 [2012-04-03 01:43 UTC] yohgaki@php.net
-Status: Open +Status: Not a bug
 [2012-04-03 01:43 UTC] yohgaki@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

unset is keyword, so you cannot use it as previous comment describes.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 16 16:00:03 2025 UTC