- mt_rand: documentation ( source)
- memory_get_usage: documentation ( source)
- ini_set: documentation ( source)
- error_reporting: documentation ( source)
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
// Variant A: servicecontainer met services in een array
class ServiceContainer
{
private $Services;
public function __construct()
{
$this->Services = array();
for ($i = 1; $i <= 100; $i++) {
$this->Services[mt_rand()] = array(
'class' => 'FileCacher',
'path' => 'some/path',
);
}
}
}
// Variant B: services met één object per service
class Service
{
public function __construct()
{
$this->Class = 'class';
$this->Path = 'some/path';
}
}
class Services
{
private $Services;
public function __construct()
{
$this->Services = array();
for ($i = 1; $i <= 100; $i++) {
$this->Services[mt_rand()] = new Service();
}
}
}
$nulmeting = memory_get_usage();
$a = new ServiceContainer();
echo '<p>Versie A verstookt ', memory_get_usage() - $nulmeting, ' bytes.</p>';
$nulmeting = memory_get_usage();
$b = new Services();
echo '<p>Versie B verstookt ', memory_get_usage() - $nulmeting, ' bytes.</p>';