0

请在这里帮助我。我有一堂课:

class Foo() {
    public function{
        if($var = x){
            do this;
        }
        else {
            do that;
        }
    }
}

和另一个类:

class B extends A() {
    public function {
        #need to import method from Foo
        #to execute on a varible in this class

      }
}

有人可以帮我解决这个问题。语言是PHP

4

2 回答 2

0
class Foo() {
    public static function test {
        if($var = x) {
            do this;
        }
        else {
            do that;
        }
    }
}


class B extends A() {

    private $variable = 2;

    public function test {
        Foo::test($this->variable);
    }
}
于 2013-10-11T19:11:22.463 回答
0
class Foo {
    protected $var;

    function __construct($var) {
        $this->var = $var;
    }

    function test() {
        echo "Method Test from class  Foo<br>";
        if ($this->var == NULL) {
            echo "Test = = Null <br>";
        }
        else {
            echo "Test != = Null <br>";
        }
    }
}

class Ftt extends Foo {
    protected $var1;

    function __construct($var, $var1) {
        $this->var1 = $var1;
        parent::__construct($var);
    }

    function test() {
        parent::test();
        echo "Method Test from class Ftt extends Foo";
        echo " with $this->var1  <br>";
    }
}

$ftt = new Ftt('notnull', 'var1');
$ftt->test('notnull');

$foo = new Foo('');
$foo->test();
于 2013-10-11T20:14:10.627 回答