Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] Fatal error: Undefined class constant obwohl sie definiert sein sollte

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Erledigt] Fatal error: Undefined class constant obwohl sie definiert sein sollte

    Hey Leute,


    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
    Hier die Klasse A:
    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
            
    {
                ... 
    Dann Klasse B:
    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] = '&lt;';
            
    $needle[11] = '[gz]';        $trans[11] = '&gt;';
            
    $needle[12] = '[code]';        $trans[12] = '<div class="code">';
            
    $needle[13] = '[/code]';    $trans[13] = '</div>';
            
    $needle[14] = '[tag]';        $trans[14] = '<div class="tag">&lt;';
            
    $needle[15] = '[/tag]';        $trans[15] = '&gt;</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;
                
            }
            
        }
    }

    ?>
    Ja, ist etwas groß, sollte aber nicht zu kompliziert sein.

    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 ); 
    Wäre euch allen sehr verbunden, wenn ihr helfen könntet. Ich verstehe nicht, warum er die Variablen nicht haben möchte.

  • #2
    Wenn du deine Gruppen per $this->groups hinzufügst, kannst du diese auch genauso auslesen und nicht per parent::groups

    Kommentar


    • #3
      Okay, danke.

      Wusste ich so nicht. Ich dachte, man macht das über parent::... ( funktioniert ja bei Funktionen ganz gut )

      Dann hat sich's das. Danke für die schnelle Hilfe

      Kommentar


      • #4
        Zitat von Areiker Beitrag anzeigen
        Ich dachte, man macht das über parent::... ( funktioniert ja bei Funktionen ganz gut )
        Bei Methoden hat das aber eine spezielle Bedeutung, du rufst eine Methode parent::X in der Regel auch NUR aus der Methode X auf um die überschiebene Methode auszuführen, um diese zu erweitern und nicht komplett zu ersetzen.
        [QUOTE=nikosch]Macht doch alle was Ihr wollt mit Eurem Billigscheiß. Von mir aus sollen alle Eure Server abrauchen.[/QUOTE]

        Kommentar

        Lädt...
        X