PHP static methods vs non-static methods/standard functions

Viewed 4646

I am working on a web app and writing pure OOP based PHP for the first time. And I have a question about static method VS standard function:

Here is an example scenario:

class Session
{
    public function start_new_session()
    {
        session_start();
        //other code here like token generator
    }
}

VS

class Session
{
    static function start_new_session()
    {
        session_start();
        //other code here like token generator
    }
}

Questions

  1. What is the difference in both?
  2. Which is better for my case?
  3. Any application? (I mean, what are the best scenario to use static method and standard function)

My Research:

I spent some time to find the answer but don't found relevant answer however I found a lot of debate and useful material. Believe me it is super hard to decide (Who is right/wrong?) for a beginner like me:

  1. In this question Someone said, It's horrible idea to use cookies in static functions and someone's saying It's a great idea

  2. And in this question: Everyone is debating on performance and some experts are saying, the static functions execute faster and some saying; functions are faster. And result also vary because of different versions of php.

Some useful stat:

PHP 5.2 : static methods are ~10-15% faster.

PHP 5.3 : non-static methods are ~15% faster

PHP 5.4 : static methods are ~10-15% faster

PHP 5.5 : static methods are ~20% faster

1 Answers
Related