This is a refactoring. It is informed by some experience, but is by no means complete.
Remove coupling with global state to make application reusable in different contexts.
Presuming you are working on an app named "flarg":
$flarg variable which is an instance of some kind of driver, rename it to $flarg_driverlib/base.php, create a global $flarg which is an instance of Flarg::Flarg::
Flarg::method() with $flarg->method(). (Possible exception: if the method is truly static, meaning it will always produce the same output given the same parameters, you might want to keep it static.)$flarg_driver is used as an example):
getDriver() method to Flarg::getDriver() return the global variable's value$flarg->getDriver()null, move initialization code into getter, but only execute when the field is null (Note, beware of introducing cycles.)When application class gets too heavy to work with, you can use ExtractClass and/or MoveMethod to split up responsibilities.
Ideally, we will eventually end up with an application object which takes all configuration as constructor parameters, does all of the application's work (probably most via delegation - FacadePattern), but does not contain any UI code. Ideal for use from command-line scripts and unit tests.