Ich habe ein Schönheitsproblem mit der Klasse Stackable.
So schaut es aktuell aus:
Lieber wärs mir natürlich, wenn ich in der setB-Methode nur so etwas machen müsste:
Erstens habe ich noch nicht verstanden, warum das nicht geht. Und zweites würd ich meine aktuelle Programmierung gern irgendwie anders - direkter gestalten.
So schaut es aktuell aus:
PHP-Code:
<?php
error_reporting(~0);
class Container extends \Stackable
{
public function setB($h, $i, $v)
{
$aV = $this['b'];
$aV[$h][$i] = $v;
$this['b'] = $aV;
}
public function getB($h, $i)
{
$aV = $this['b'];
if
(
!array_key_exists($h, $aV) ||
!array_key_exists($i, $aV[$h])
)
throw new Exception('b');
return $aV[$h][$i];
}
public function getAllB()
{
return $this['b'];
}
}
$oC = new Container();
$oC->setB(0, 0, 100);
$oC->setB(5, 3, 200);
var_dump($oC->getAllB());
?>
PHP-Code:
$this['b'][$h][$i] = $v;
Kommentar