johnny johnny - 1 year ago 47
PHP Question

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

/**** static functions ****/
function start() {
// Prep basic translation support

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

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

return $ost;

In another file, this is done:


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

EDIT: Does this work in other languages?


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.