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.
What do you mean by the script being a class ?
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 (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).
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
What do you mean by the script being a class ?
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 (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).
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().
What do you mean by the script being a class ?
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 (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).