any special meaning of MAIN() ?
Moderator: General Moderators
any special meaning of MAIN() ?
I have seen some PHP source code, people often define a MAIN function inside a class, as I am new to write PHP but I know C/C++. I just wonder this MAIN has any special meaning in the class or not?
Though I did search the php manual and found that MAIN() shoud has nothing to do with the constructor, but just curious about the reason why I saw it often? It is just a coding custom or really something else?
Thanks for any help in advance,
echo
Though I did search the php manual and found that MAIN() shoud has nothing to do with the constructor, but just curious about the reason why I saw it often? It is just a coding custom or really something else?
Thanks for any help in advance,
echo
Re: any special meaning of MAIN() ?
No special meaning, and personally - I've never seen it being used, so I guess it's not that common.
Re: any special meaning of MAIN() ?
Thank you for your reply. But I did seen some so I ask, like the source code of phpbb3 and some other open source package. 
Re: any special meaning of MAIN() ?
Probably a practice carried over from someone familiar with Java/C programming, where main() is the constructor of a class (I think).
As far as PHP is concerned, the main() function holds no special significance, and can just as easily be called stinkyBlueShoes().
As far as PHP is concerned, the main() function holds no special significance, and can just as easily be called stinkyBlueShoes().
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: any special meaning of MAIN() ?
Thanks pickle, thank you for your reply.
I also doubt the main() is used as the constructor or sort like, but I can not find anything to confirm this doubt. Under C++ the constructor and destructor would be called automatically by the instance of class, would the main() be called auto or not? If yes, can anyone help to explain how does it work?
Or it is just called by $foo->main() or $this->main()?
I also doubt the main() is used as the constructor or sort like, but I can not find anything to confirm this doubt. Under C++ the constructor and destructor would be called automatically by the instance of class, would the main() be called auto or not? If yes, can anyone help to explain how does it work?
Or it is just called by $foo->main() or $this->main()?
Re: any special meaning of MAIN() ?
main is just a function / method name. It does not bear any specific mean as far as PHP concerned. In PHP constructor is called '__construct' and destructor is called '__destruct'eko4v wrote: I also doubt the main() is used as the constructor or sort like, but I can not find anything to confirm this doubt. Under C++ the constructor and destructor would be called automatically by the instance of class, would the main() be called auto or not?
Yes, that's right. Also it could be called ClassName::main() if it's defined as staticOr it is just called by $foo->main() or $this->main()?
Re: any special meaning of MAIN() ?
Guys,
Thanks for your help to clear my confusion, I got it now.
echo
Thanks for your help to clear my confusion, I got it now.
echo
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: any special meaning of MAIN() ?
FYI, public static main() is the first function called when the program starts. The constructor is the same name as the class (in Java anyways).pickle wrote:Probably a practice carried over from someone familiar with Java/C programming, where main() is the constructor of a class (I think).
Re: any special meaning of MAIN() ?
Ah right - I knew it had some significance.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: any special meaning of MAIN() ?
Not in PHP.pickle wrote:Ah right - I knew it had some significance.
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: any special meaning of MAIN() ?
Perhaps slightly
but ...
C# too. Prefer the PHP 5 approach of using __construct() and __destruct() though, which to my mind makes more sense.Jonah Bron wrote:FYI, public static main() is the first function called when the program starts. The constructor is the same name as the class (in Java anyways).