Pre: I am looking at a quite big PHP project developed by a company which we need to partly interact with while building a new webapp.
The whole application is developed in PHP 5.
Most of the classes in this project, and in particular all the classes that interact with the database, are declared abstract
and contain only static
functions.
Take for example this file:
abstract class DataHelper_Command
{
/**
* @param unknown $id_device
* @param unknown $latest_command_id
* @return Command[]
*/
public static function getCommandsToSend($id_device, $latest_command_id)
{
$rows = DBUtility::executePreparedQuery('SPS_COMMANDS_TO_SEND', array(":id_device" => $id_device, ":latest_command_id" => $latest_command_id));
return DataHelper_Command::commandsFromDataTable($rows);
}
public static function getFW()
{
$rows = DBUtility::executePreparedQuery('SPS_FW_VERSION');
return $rows;
}
/**
* @param unknown $rows
* @return Command[]
*/
private static function commandsFromDataTable(&$rows)
{
$res = array();
foreach ($rows as &$row)
{
$res[] = DataHelper_Command::commandFromDataRow($row);
}
return $res;
}
/**
* @param array $row
* @return Command
*/
private static function commandFromDataRow(&$row)
{
return new Command($row["id_command"], $row["type"], $row["text"]);
}
}
I don't even see any trace of using a Singleton pattern in the project!
That sounds a bit strange to me, as I always heard that using static classes is a nightmare in terms of performance.
This server was meant to be able to run on both standard webservers and on a really performance-limited embedded device (An ARM running at 400MHz, with 128 MB of RAM).
Am I missing something here? Are there any use-cases in which this is considered a good practice?