Can I really use methods named like 'stat', 'fopen'?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
exesteam
Forum Newbie
Posts: 5
Joined: Mon Jan 19, 2009 6:27 pm

Can I really use methods named like 'stat', 'fopen'?

Post by exesteam »

Hello

Looks like PHP works fine even if I use names that are reserved. An example

Code: Select all

class test {
function fopen() {}
function stat() {}
}
No problems? Is this because the class makes a new namespace?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Can I really use methods named like 'stat', 'fopen'?

Post by Mark Baker »

exesteam wrote:Is this because the class makes a new namespace?
Effectively.
If you execute stat() it will still execute the standard PHP stat function.
You can only execute the stat that you've written in your class as $objID->stat() - for an instance of the test class called $objID, or as $this->stat() from within the class.
Even if the method was defined as static, you'd still need to use test::stat() or self::stat()
Post Reply