请在这里帮助我。 我有一节课:
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
答案 0 :(得分: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);
}
}
答案 1 :(得分: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();