Yes a singleton object to have an application context as shown below. But the constructor and the destruct function/methods get invoked for every request.
Is there a way to hold objects from getting garbage collected/destroyed between requests?
<?php
final class ApplicationContext
{
private static $inst = null;
public static function Instance()
{
if ($inst === null) {
$inst = new ApplicationContext();
}
return $inst;
}
private function __construct()
{
echo "constructor <br/>";
}
public function __destruct() {
echo "destroyed <br/>";
}
}
ApplicationContext::Instance();