How to define and use a a base class and an extension of the class in PHP

1 Answer

0 votes
class profession 
{
   var $iam;

   function profession($prof) 
   {
       $this->iam = $prof;
   }
   function set_profession($prof) 
   {
       $this->iam = $prof;
   }
   function print_profession() 
   {
       echo $this->iam;
   }
}
class worker extends profession 
{
   var $name;
   var $age;

   function worker($name, $age, $prof) 
   {
       $this->name = $name;
       $this->age = $age;
       $this->set_profession($prof);
   }
   function print_all() 
   {
       echo $this->name . " " . $this->age . " ";
       echo $this->print_profession();
   }
}


$w1 = new worker("dan", 47, "programmer");
$w1->print_all();


/*
run:

dan 47 programmer

*/

 



answered Jun 28, 2015 by avibootz

Related questions

1 answer 195 views
195 views asked May 30, 2016 by avibootz
1 answer 255 views
1 answer 229 views
3 answers 305 views
1 answer 216 views
216 views asked Jun 28, 2015 by avibootz
1 answer 191 views
1 answer 260 views
260 views asked Apr 12, 2015 by avibootz
...