FAQ
Hello there :]

I wanted to build a method called "list". The problem is that once I
do that, I get a
"PHP Parse error: syntax error, unexpected T_LIST, expecting T_STRING"
error, because it's a "language construct".

Here's the code that leads me to this error :

<?php
class Foo {
function __construct () {

}
function list () {
echo "Hello";
}
}
$bar = new Foo ();
$bar->list();
?>

So I made it working with a "__call" magic method, like this :

<?php
class Foo {
function __construct () {

}
function __call ($name, $arguments) {
echo "Hello";
}
}
$bar = new Foo ();
$bar->list();
?>

And it works. So there's my question : why can't we make methods with
the same name as those used by "language constructs" ? I don't see
the point. Even less if you can make it work with the __call magic
method.

Does someone have an explanation ? Is there a way to make this
possible for future versions of PHP, so that the classes namespace is
really independent ?

Don't tell me to use another name. Writting code like :
$books->list('all');
or :
class Books extends Controller {
function list () {
# Instructions to list all books
}
}
makes things so much easier to read and self explanatory than
putting, for example, a "_" in front of it (_list).

Thanks :]

Urbanose

Search Discussions

  • Antony Dovgal at Dec 4, 2006 at 2:31 pm

    On 12/04/2006 05:22 PM, Urbanose wrote:
    And it works. So there's my question : why can't we make methods with
    the same name as those used by "language constructs" ? I don't see
    the point.
    http://www.php.net/manual/en/reserved.php
    The point is that these names are reserved by the parser and cannot be used for other purposes.

    --
    Wbr,
    Antony Dovgal

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedDec 4, '06 at 2:23p
activeDec 4, '06 at 2:31p
posts2
users2
websitephp.net

2 users in discussion

Antony Dovgal: 1 post Urbanose: 1 post

People

Translate

site design / logo © 2022 Grokbase