2013-10-11 4 views
1

여기에서 도와주세요. 나는클래스에서 다른 클래스의 자식으로 호출하는 PHP

class Foo() { 
    pubic 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

입니까? – gh123man

+0

B가 A를 확장하고 있다면, 당신은 단순히 $ b = new B(); $ B-> methodDefinedInA ($ var_from_B)' –

+0

죄송합니다. Foo 클래스의 메소드를 호출해야한다는 의미였습니다. – OyugiK

답변

0
class Foo(){ 
    pubic 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); 

    } 
} 
+0

위대한 사람이 정말 좋은이 – OyugiK

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(); 
+0

이 고마워 녀석을 사랑해 – OyugiK

관련 문제