johnny
johnny

Reputation: 19735

Why can I call a PHP function in a class statically without the method having been declared the static keyword?

This code is from osTicket, https://github.com/osTicket/osTicket/blob/1.9.x/main.inc.php,

   /**** static functions ****/
    function start() {
        // Prep basic translation support
        Internationalization::bootstrap();

        if(!($ost = new osTicket()))
            return null;

        //Set default time zone... user/staff settting will override it (on login).
        $_SESSION['TZ_OFFSET'] = $ost->getConfig()->getTZoffset();
        $_SESSION['TZ_DST'] = $ost->getConfig()->observeDaylightSaving();

        // Bootstrap installed plugins
        $ost->plugins->bootstrap();

        // Mirror content updates to the search backend
        $ost->searcher = new SearchInterface();

        return $ost;
    }

In another file, this is done:

osTicket::start()

It works. How come the static keyword isn't required?

EDIT: Does this work in other languages?

Upvotes: 0

Views: 53

Answers (1)

johannes
johannes

Reputation: 15969

For historic reasons. PHP 4 didn't have the static keyword and many code bases used members statically. Fixing such old code base is hard and enforcing this would have prevented adoption.

Upvotes: 2

Related Questions