[PHP] Kleines Klassen-/Array Problem



  • Hi!

    <?php
    
    $Template = new cTemplate;
    $Template->Insert("NAME",   "Test");
    $Template->Insert("MEMBER", "Abc");
    $Template->Draw();
    
    class cTemplate
    {
    	private $Fields;
    
    	public function Insert($Name, $Value)
    	{
    		$this->$Fields[$Name] = $Value;
    	}
    
    	public function Delte($Name)
    	{
    		unset($this->$Fields[$Name]);
    	}
    
    	public function Update($Name, $Value)
    	{
    		$this->$Fields[$Name] = $Value;
    	}
    
    	public function Draw()
    	{
    		echo $this->$Fields;
    	}
    }
    
    ?>
    

    Er meckert mal wieder sehr aufschlussreich mit

    Fatal error: Cannot access empty property in D:\XAMPP\xampp\htdocs\test.php on line 14

    Zeile 14 ist

    $this->$Fields[$Name] = $Value;
    

    mfg olli



  • Falsch:

    $this->$Fields
    

    Richtig:

    $this->Fields
    

    😉

    Grüße,
    Marc



  • Danke dir!


Anmelden zum Antworten