habe gerade ein Problem, das ich nicht verstehe.
Ich habe eine Datei, die auf eine Klasse A zugreift, die wiederum als Parent eine andere Klasse B hat - sowei nicht das Ding.
Das Problem ist, dass wenn A auf Variablen von B zugreifen möchte, die EIGENTLICH definiert sein sollten, ich disen Fehler bekomme:
Code:
Fatal error: Undefined class constant 'groups' in C:\Users\... on line 20
PHP-Code:
require_once( 'stationHandler.class.php' );
class stationDesigner extends stationHandler{
public function __construct( $xmlStationFile, $xmlUserFile )
{
parent::__construct( $xmlStationFile, $xmlUserFile );
}
public function createStationIndex()
{
$result = '<div id="stationIndex">';
foreach( parent::groups as $group ) //<---- line 20
{
...
PHP-Code:
<?php
class stationHandler{
public $stationObj;
public $userObj;
public $stationArray;
public $userArray;
public $groups;
public function __construct( $xmlStationFile, $xmlUserFile )
{
if( file_exists( $xmlStationFile ) && file_exists( $xmlUserFile ) )
{
$this->stationObj = simplexml_load_file( $xmlStationFile );
$this->userObj = simplexml_load_file( $xmlUserFile );
self::loadStationArray();
self::loadUserArray();
self::loadGroups();
}
else
{
echo( '[StationHandler] ERROR: Die angegebenen Dateien existieren nicht!' );
}
}
private function loadStationArray()
{
foreach( $this->stationObj->station as $station )
{
$stationID = intval( $station->id );
$this->stationArray[$stationID] = array(
'needed' => strval( $station->needed ),
'code' => strval( $station->doneCode ),
'group' => strval( $station->group ),
'title' => strval( $station->title ),
'content' => self::translateContent($station->content),
'exerc' => self::formateExercises($station->exercises) );
}
}
private function translateContent( $content )
{
$needle[0] = '[title]'; $trans[0] = '<mark>';
$needle[1] = '[/title]'; $trans[1] = '</mark>';
$needle[2] = '[link '; $trans[2] = '<a ';
$needle[3] = '[/link]'; $trans[3] = '</a>';
$needle[4] = '[br]'; $trans[4] = '<br>';
$needle[5] = 'href='; $trans[5] = 'href=';
$needle[7] = '[dbr]'; $trans[7] = '<br><br>';
$needle[8] = '[mark]'; $trans[8] = '<font class="mark">';
$needle[9] = '[/mark]'; $trans[9] = '</font>';
$needle[10] = '[kz]'; $trans[10] = '<';
$needle[11] = '[gz]'; $trans[11] = '>';
$needle[12] = '[code]'; $trans[12] = '<div class="code">';
$needle[13] = '[/code]'; $trans[13] = '</div>';
$needle[14] = '[tag]'; $trans[14] = '<div class="tag"><';
$needle[15] = '[/tag]'; $trans[15] = '></div>';
$needle[100] = ']'; $trans[100] = ' target="_blank">';
return str_replace( $needle, $trans, $content);
}
private function formateExercises( $exercises )
{
$result = array();
foreach( $exercises->ex as $ex )
{
$exNo = intval( $ex->no );
if( isset( $ex->description ) )
{
$result[$exNo] = strval( $ex->description );
}
elseif( isset( $ex->done ) )
{
$result[$exNo] = strval( $ex->done );
}
}
return $result;
}
private function loadUserArray()
{
foreach( $this->userObj->station as $stationSave )
{
$stationID = intval( $stationSave->id );
$this->userArray[$stationID] = array(
'done' => strval($stationSave->done),
'exerc' => self::formateExercises( $stationSave->exercises ));
}
}
private function loadGroups()
{
$this->groups = array();
foreach( $this->stationArray as $stations )
{
if( empty( $this->groups ) )
{
$this->groups[1] = $stations['group'];
}
else
{
foreach( $this->groups as $groups )
{
if( $stations['group'] == $groups )
{
$groupExists = TRUE;
}
if( !isset( $groupExists ) )
{
$groupExists = FALSE;
}
}
if( $groupExists != TRUE )
{
array_push( $this->groups, $stations['group'] );
}
unset( $groupExists );
}
}
}
public function isDone( $stationID )
{
$userSave = $this->userArray[$stationID];
if( $userSave['done'] == 'true' )
{
return TRUE;
}
else
{
return FALSE;
}
}
public function isLocked( $stationID )
{
$station = $this->stationArray[$stationID];
$neededStation = $station['needed'];
if( self::isDone( $neededStation ) == TRUE )
{
return TRUE;
}
else
{
return FALSE;
}
}
}
?>
Und hier wird Klasse A aufgerufen:
PHP-Code:
require( 'assets/php/class/stationDesigner.class.php' );
$stationFile = 'assets/xml/stations.xml';
$userFile = 'assets/xml/userSaves/userSave.xml';
$designer = new stationDesigner( $stationFile, $userFile );
Einen Kommentar schreiben: