Object execution

php.internals

Jesse Binam

21 years ago
Any thoughts on the idea of a magic method called "__main()" or "__exec()" that would be called if the script being executed is a class.

Nicolas Bérard Nault

21 years ago
What do you mean by the script being a class ? On 6/28/05, Jesse Binam <sirbinam@gmail.com> wrote:
> Any thoughts on the idea of a magic method called "__main()" or > "__exec()" that would be called if the script being executed is a > class. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- Nicolas Bérard Nault (nicobn@gmail.com) "Maybe nature is fundamentally ugly, chaotic and complicated. But if it's like that, then I want out." -- Steven Weinberg (prix Nobel de physique, 1979).

Jesse Binam

21 years ago
For example... --- example.php --- <?php class Example { public function __main() { echo "Hello World!"; } } ?> --- end example.php --- `php -q example.php` would output "Hello World!" With this you could potentially eliminate the global scope if you chose to. For the record, by no means do I want PHP to be Java. I just think this feature would be a nice finishing touch to a very OOP style app. Otherwise you basically have to have a one liner to call something like app::run(). On 6/28/05, Nicolas Bérard Nault <nicobn@gmail.com> wrote:

Al Baker

21 years ago
I think it means being able to scope the default execution block for a script. Normally script goes from top-to-bottom dipping into each include and compiles and executes them in a linear fashion. Perhaps having a main would hold off on the execution part until you got to the main() and from there, only execute that which is used inside that block and then exit. The "main method of a class" idea I always felt was unnatural in Java. A C/C++ style main() as I describe above could be interesting. I wonder if it has any compelling benefits to it, or rather what would the advantage be over how PHP is executed today? Al On Tue, 2005-06-28 at 18:36 -0400, Nicolas Bérard Nault wrote: