সর্বশেষ সম্পাদনা করেছেন nhosen2 (০৬-১২-২০১৬ ২১:০০)

টপিকঃ inheritence এ একটু প্রবলেম

<?php

class parents{

    public $age;
    public $name;
    public $sex;


    public function __construct($age,$name,$sex){
        $this->age = $age;
        $this->name = $name;
        $this->sex = $sex;
    }
    parent::childs
    public function parentsinfo(){
        echo "Parents age is : ".$this->age."<br>";
        echo "Parents name is : ".$this->name."<br>";
        echo "Parents sex is : ".$this->sex."<br>";
    }

}

class childs extends parents{

    public function childinfo(){
        echo "child age is : ".$this->age."<br>";
        echo "child name is : ".$this->name."<br>";
        echo "child sex is : ".$this->sex."<br>";
    }
}

$stparents = new parents(23,"nazmul","male");
$stparents->parentsinfo();

$childs-> new parents(1,"usman","male");
$childs->childinfo();

?>

এখানে শেষের দিকের $childs-> new parents(1,"usman","male"); এই লাইনে এরর আসে  কেন ? আমি তো আগের ক্লাসের সাব ক্লাসকে কল করেছি ।

Re: inheritence এ একটু প্রবলেম

<?php

class parents{

    public $age;
    public $name;
    public $sex;


    public function __construct($age,$name,$sex){
        $this->age = $age;
        $this->name = $name;
        $this->sex = $sex;
    }
    
    public function parentsinfo(){
        echo "Parents age is : ".$this->age."<br>";
        echo "Parents name is : ".$this->name."<br>";
        echo "Parents sex is : ".$this->sex."<br>";
    }

}

class childs extends parents{

    public function childinfo(){
        echo "child age is : ".$this->age."<br>";
        echo "child name is : ".$this->name."<br>";
        echo "child sex is : ".$this->sex."<br>";
    }
}

$stparents = new parents(23,"nazmul","male");
$stparents->parentsinfo();

$childs =  new childs(1,"usman","male");
$childs->childinfo();

Re: inheritence এ একটু প্রবলেম

forhan লিখেছেন:
<?php

class parents{

    public $age;
    public $name;
    public $sex;


    public function __construct($age,$name,$sex){
        $this->age = $age;
        $this->name = $name;
        $this->sex = $sex;
    }
    
    public function parentsinfo(){
        echo "Parents age is : ".$this->age."<br>";
        echo "Parents name is : ".$this->name."<br>";
        echo "Parents sex is : ".$this->sex."<br>";
    }

}

class childs extends parents{

    public function childinfo(){
        echo "child age is : ".$this->age."<br>";
        echo "child name is : ".$this->name."<br>";
        echo "child sex is : ".$this->sex."<br>";
    }
}

$stparents = new parents(23,"nazmul","male");
$stparents->parentsinfo();

$childs =  new childs(1,"usman","male");
$childs->childinfo();

কিছুই বুঝলাম না ।

Re: inheritence এ একটু প্রবলেম

remove this line:

parent::childs
Calm... like a bomb.