ok, ich hab mich gestern noch gespielt, weiß jetzt ungefähr woran es scheitert:
ich post mal die auszüge, die damit was zu tun haben:
class A {
var $blocks = array(); //array, in dem die block-objekte gespeichert sind (siehe tblock.inc.php)
function defineBlock ($blockname) {
$blockcode = ... //blockcode extrahieren aus best. daten
$tmpBlock = new B ($blockname);
$tmpBlock->setBlockCode ($blockcode);
array_push($this->blocks, $tmpBlock);
}
function setVariables ($blockname, $varArray) {
foreach ($this->blocks as $currentBlock) {
if ($currentBlock->getBlockName() == $blockname) {
$currentBlock->setValues($varArray);
break;
}
}
}
function output () {
for ($i=0; $i<sizeof($this->blocks); $i++) {
$currentBlock = $this->blocks[0];
$parsecode = str_replace ($currentBlock->getBlockCode, $currentBlock->parseBlock(), $parsecode);
}
return $parsecode;
}
}
class B {
var $name;
var $blockcode;
var $values = array();
function TBlock ($blockname) {
if (is_string($blockname)) {
return $this->name=$blockname;
}
}
function setBlockCode ($code) {
//-- setzt den Code --//
$this->blockcode = chop($code);
}
function setValues ($valArray) {
array_push($this->values, $valArray); //das ist die problemzeile
}
function parseBlock () {
foreach ($this->values as $valArray) {
$currentBlockCode = $this->blockcode;
foreach ($valArray as $key => $name) {
$currentBlockCode = str_replace ($key, $name, $currentBlockCode);
}
$returnString .="\n $currentBlockCode";
}
return $returnString;
}
}
ok, das müssts jetzt im wesentlichen gewesen sein.
der fehler is übrigens folgender:
benutzt ich im test-script nur die klasse B, so funktioniert alles ganz normal.
will ich B über A benutzen (also ein array aus B-objekten), setzt mir array_push($this->values, $valArray) irgendwas, aber nicht das array.
sprich bei einer ausgabe mit sizeof($this->values) in anderen funktionen (wie zB parseBlock) wird mir immer 0 zurückgegeben.
sollt das nicht ausreichen, kann ich euch das programm mailen.
|