php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51709 Naming a class method using a reserved keyword causes a parser error
Submitted: 2010-04-30 22:33 UTC Modified: 2011-09-01 21:53 UTC
From: razvan dot gavril at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Ubuntu 10.04 LTS
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: razvan dot gavril at gmail dot com
New email:
PHP Version: OS:

 

 [2010-04-30 22:33 UTC] razvan dot gavril at gmail dot com
Description:
------------
Is no longer possible to name a class methods using names that are reserved keywords like : 'break', 'for', 'goto'.  It used to work with previous php versions.

If this is a 'feature', what's the point ?




Test script:
---------------
<?php

class foo {
        static function for() {
                echo "1";
        }

        static function goto() {
                echo "2";
        }

}

foo::for();
foo::goto();

Expected result:
----------------
Display: 12


Actual result:
--------------
PHP Parse error:  syntax error, unexpected T_FOR, expecting T_STRING in /etc/asterisk/manager.d/test.php on line 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-12 18:37 UTC] sixd@php.net
-Status: Open +Status: Bogus
 [2010-05-12 18:37 UTC] sixd@php.net
I don't know what your "previous" version was, but the same error occurs with PHP 
5.1.6 so this has been a language feature for a very long time.

Also see http://bugs.php.net/51782 about the introduction of new keywords in 
recent versions.
 [2010-05-12 19:05 UTC] razvan dot gavril at gmail dot com
Strange, I've notice the bug after updating from Ubuntu karmic. Looking now at 
the package.ubuntu.com I see that karmic came with php 5.2.10

I'm 100% sure that I didn't had this bug before the update
 [2010-05-12 19:13 UTC] razvan dot gavril at gmail dot com
I notice that the other bug you've pointed me to, states that the problem 
happens starting with version 5.3.2 also.
 [2011-09-01 21:53 UTC] tyrael@php.net
for the record:
I've tested this, and the last 5.2 version(5.2.17) behaves the same way:

Parse error: syntax error, unexpected T_FOR, expecting T_STRING in 
/home/tyrael/testbug.php on line 3

Tyrael
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC