# Making a method called "list" or other "language constructs" names.

- Thread: https://externals.io/message/26789
- Original archive: https://news-web.php.net/php.internals/26789
- Started by Urbanose on 2006-12-04T14:22:15+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #26790 — Antony Dovgal — 2006-12-04T13:49:25+00:00

URL: https://externals.io/message/26789#26790 · In reply to: #26789

> 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

---

## #26789 — Urbanose — 2006-12-04T14:22:15+00:00

URL: https://externals.io/message/26789#26789

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
