Possible Duplicate:
Is there a way to program 100% object-oriented in PHP?
What I am trying to accomplish would look something like this:
<?php
//index.php
class Site{
public static function main(){
// starts all the processing of the site
}
}
?>
So that when someone visits the site's index.php
the site will start up without having any code outside the class.
Yes I know that I could use __autoload
or even spl_autoload_register
to handle autoloading of classes but that would still most likely need to be added outside of the class.
I have my doubts that this is possible but I don't know why this wouldn't be possible.
The static keyword is used to declare properties and methods of a class as static. Static properties and methods can be used without creating an instance of the class. The static keyword is also used to declare variables in a function which keep their value after the function has ended.
new static instantiates a new object from the current class, and works with late static bindings (instantiates the subclass if the class was subclassed, I expect you understand that). Having a static method on a class which returns a new instance of same is an alternative constructor.
Methods are used to perform actions. In Object Oriented Programming in PHP, methods are functions inside classes. Their declaration and behavior are almost similar to normal functions, except their special uses inside the class.
It's a static method, so ... it does not need to be accessed within the context of an instantiated object. You can just, you know, call it from your public static void main(...) method. If the class that contains your main() method is named Employee, then...
No.
Java's entry point is defined as the main
method. PHP's entry point is defined as the first line in the first file that gets executed. You will have to start with "procedural" code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With