Mailinglisten-Archive |
Hab folgendes Beispiel und möcht gerne wissen, wieso ich vor
Z35:
$this->objId->strFgstNr = $strFgstNr;
kein:
$this->objId = new FzgIdKlasse();
einfügen muss.
Code:
<?
class FzgIdKlasse
{
var $strFgstNr;
var $strHerstNr;
}
class FahrzeugKlasse{
var $objId;
var $nBaujahr;
function __clone(){
$this->objId = new FzgIdKlasse();
$this->objId->strFgstNr = 'undef';
$this->objId->strHerstNr = 'undef';
}
}
class AutoKlasse extends Fahrzeugklasse{
var $strMarke, $strTyp;
function AutoKlasse($strMarke,
$strTyp,$nBaujahr,$strFgstNr,$strHerstNr){
$this->strMarke = $strMarke;
$this->strTyp = $strTyp;
$this->nBaujahr = $nBaujahr;
$this->nBaujahr = $nBaujahr;
$this->objId->strFgstNr = $strFgstNr;
$this->objId->strHerstNr = $strHerstNr;
}
function __clone(){
FahrzeugKlasse::__clone();
}
function getDaten(){
$strTmp = 'Ich bin ein '.$this->strMarke;
$strTmp .= ' '.$this->strTyp.'<br>';
$strTmp .= 'Baujahr '.$this->nBaujahr.'<br>';
$strTmp .= 'FgstNr '.$this->objId->strFgstNr.'<br>';
$strTmp .= 'Code '.$this->objId->strHerstNr.'<br><br>';
return $strTmp;
}
}
$objA = new Autoklasse('mercedes','300sl',1954,'11111','0710');
$objB = clone $objA;
$objB->nBaujahr = 1990;
$objB->objId->strFgstNr = '222222';
echo $objB->getDaten().'<br>';
echo $objA->getDaten().'<br>';
?>
php::bar PHP Wiki - Listenarchive