Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Inheritance in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 174
    Comment on it

     Inheritance is a principle of OOP'S(Object Oriented Programming Language) in which a user can inherit all the properties of above class. The class who inherit the another class know as Child Class and the class which is being inherited called as parent class. Re-Usability of code can pe possible using the concept of inheritance, here we use php_div and php_span and php_form and using different class because its all different in nature.

    class PHP
    {
    protected $name;
    protected $id;
    protected function basicAttribute
    {
    return "name='$this->name' id='$this->id'";
    }
    }
    Class PHP_div extends PHP
    {
    public function __construct($id , $name)
    {
    $this->id = $id;
    $this->name = $name;
    }
    public function getDiv($content)
    {
    $basicAttribute = $this->basicAttribute();
    return "<div $basicAttribute >$content</div>"
    }
    }
    Class PHP_span extends PHP
    {
    public function __construct($id , $name)
    {
    $this->id = $id;
    $this->name = $name;
    }
    public function getSpan($content)
    {
    $basicAttribute = $this->basicAttribute();
    return "<span $basicAttribute >$content</span>"
    }
    }

    In the above line of code user can access all method i.e protected and public from PHP class it is directly accessible in your class PHP_div and PHP_span class.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: