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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to