Reputation: 9173
I have declared a method for my class called list()
, and to avoid its colliosn/error with PHP's own list()
function, put it in a namespace. But unfortunately I still get the error. Her is scenario:
I have declared a namespace at the top of my file:
<?php namespace MyNameSpace\ThisClass;
use MyNameSpace\ThisClass;
And then the class:
Class AClass
{
function list()
{
// something here
}
}
And then instanciate it.
$x = MyNameSpace\ThisClass\AClass();
I have declared the class in a namespace and expecting it to ignore list()
method collision with PHP's own list()
function. However, php throws following error:
syntax error, unexpected 'list' (T_LIST), expecting identifier (T_STRING)
Why I still get the error considering the fact that my list() function is nested in a namespace?
Upvotes: 3
Views: 894
Reputation: 10132
As from PHP Docs:
These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on - but they're not, really: they are language constructs. You cannot use any of the following words as constants, class names, function or method names. Using them as variable names is generally OK, but could lead to confusion.
Reserved words like:
list()
die()
include_once()
Upvotes: 8