PHP -Methode der Elternklassen aufrufenPhp

PHP-Programmierer chatten hier
Anonymous
 PHP -Methode der Elternklassen aufrufen

Post by Anonymous »

Code: Select all

class Foo {
protected static $a = 1;
protected $b = 2;

public function func() { return 'foo' . static::$a . $this->b; }
}
class Bar extends Foo {
protected static $a = 3;
protected $b = 4;

public function func() { return 'bar' . static::$a . $this->b; }
}

$obj = new Bar();
$obj->func(); // returns of course 'bar34'
< /code>

Gibt es in PHP eine Option, um Func () aus der Foo -Klasse aufzurufen?Bar* obj = new Bar();
Foo* obj2 = (Bar*) obj;
obj2->func(); // returns 'foo14';

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post