Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a PHP equivalent for `public static main(String[] args)` in Java? [duplicate]

Tags:

oop

php

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.

like image 601
JRSofty Avatar asked Sep 04 '12 10:09

JRSofty


People also ask

What is static method PHP?

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.

What is new static PHP?

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.

What are PHP methods?

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.

How do you call a static method from the main class in Java?

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...


1 Answers

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.

like image 76
deceze Avatar answered Sep 21 '22 12:09

deceze