Three class extended to one class I built this 4 classes where the Main is the one responsible for setting and getting the variables. I am using PHP7.1. Please let me know on how to make this more amazing or maybe using trait. How does my classes look? Is it professionally made? what do you guys think? thank you very much!

&lt;?php

class Main
{
    // Parameters
    protected $first_name;
    protected $middle_name;
    protected $last_name;

    public function first_name($first_name)
    {
        $this-&gt;first_name = $first_name;
        return $this;
    }

    public function middle_name($middle_name)
    {
        $this-&gt;middle_name = $middle_name;
        return $this;
    }

    public function last_name($last_name)
    {
        $this-&gt;last_name = $last_name;
        return $this;
    }
}

class Cpc extends Main
{
    public function __construct()
    {
        echo 'this cpc construct &lt;br&gt;';
    }

    public function generateCpc()
    {
        echo 'this cpc generated &lt;br&gt;';
        echo $this-&gt;first_name." ".$this-&gt;middle_name." ".$this-&gt;last_name;
        echo '&lt;br&gt;';
    }
}

class Basetable extends Cpc
{
    public function __construct()
    {
        echo 'this basetable construct &lt;br&gt;';
    }

    public function generateBasetable()
    {
        echo 'this basetable generated &lt;br&gt;';
        echo $this-&gt;first_name." ".$this-&gt;middle_name." ".$this-&gt;last_name;
        echo '&lt;br&gt;';
    }
}

class Layer extends Basetable
{
    public function __construct()
    {
        echo 'this layer construct &lt;br&gt;';
    }

    public function generateLayer()
    {
        echo 'this layer generated &lt;br&gt;';
        echo $this-&gt;first_name." ".$this-&gt;middle_name." ".$this-&gt;last_name;
        echo '&lt;br&gt;';
    }
}

class Master extends Layer
{
    public function __construct()
    {
        echo 'this Master construct &lt;br&gt;';
    }

    public function generate()
    {
        $this-&gt;generateCpc();
        $this-&gt;generateBasetable();
        $this-&gt;generateLayer();

        echo 'this master generated &lt;br&gt;';
        echo $this-&gt;first_name." ".$this-&gt;middle_name." ".$this-&gt;last_name;
        echo '&lt;br&gt;';
    }
}

$o = new Master();
$o-&gt;first_name('ken dan')-&gt;middle_name('sunico')-&gt;last_name('tinio')-&gt;generate();

?&gt;
Basically, this structure makes very little sense by itself, without knowing the real purpose of all these classes and the similarities worth extending.

But some suggestions could be made anyway.


whatever class that is intended to display some data, by definition cannot have a property like first name. First names are generally belong to persons. A class must represent a solid entity, not a Frankenstein constructed from different parts. So in your place I would avoid creating such entities as cyborgs, that bear both human-like and machine-like features. Whatever belongs to a person, goes to one class, and whatever belongs to a table renderer belongs to another class.
There is a PHP coding standard, and you are supposed to follow its guidelines.


So, for as little information as provided in your question, here is a class structure I propose for you:

There is a class Person that holds the person's personal information,

class Person
{
    // Parameters
    protected $firstName;
    protected $middleName;
    protected $lastName;

    public function __construct($firstName, $middleName, $lastName)
    {
        $this-&gt;firstName = $firstName;
        $this-&gt;middleName = $middleName;
        $this-&gt;lastName = $lastName;
    }

    public function setFirstName($firstName)
    {
        $this-&gt;firstName = $firstName;
        return $this;
    }

    public function setMiddleName($middleName)
    {
        $this-&gt;middleName = $middleName;
        return $this;
    }

    public function setLastName($lastName)
    {
        $this-&gt;lastName = $lastName;
        return $this;
    }

    public function getFirstName()
    {
        return $this-&gt;firstName;
    }

    public function getMiddleName()
    {
        return $this-&gt;middleName;
    }

    public function getLastName()
    {
        return $this-&gt;lastName;
    }
}


and a class Output that renders tables.

class Output
{
    protected $person;

    public function __construct(Person $person)
    {
        echo 'this Master construct &lt;br&gt;';
        $this-&gt;person = $person;
    }

    protected function generateCpc()
    {
        echo 'this cpc generated &lt;br&gt;';
        echo $this-&gt;person-&gt;getFirstName()." ".$this-&gt;person-&gt;getMiddleName()." ".$this-&gt;person-&gt;getLlast_name;
        echo '&lt;br&gt;';
    }

    protected function generateBasetable()
    {
        echo 'this basetable generated &lt;br&gt;';
        echo $this-&gt;person-&gt;getFirstName()." ".$this-&gt;person-&gt;getMiddleName()." ".$this-&gt;person-&gt;getLlast_name;
        echo '&lt;br&gt;';
    }

    protected function generateLayer()
    {
        echo 'this layer generated &lt;br&gt;';
        echo $this-&gt;person-&gt;getFirstName()." ".$this-&gt;person-&gt;getMiddleName()." ".$this-&gt;person-&gt;getLlast_name;
        echo '&lt;br&gt;';
    }

    public function generate()
    {
        $this-&gt;generateCpc();
        $this-&gt;generateBasetable();
        $this-&gt;generateLayer();

        echo 'this master generated &lt;br&gt;';
        echo $this-&gt;person-&gt;getFirstName()." ".$this-&gt;person-&gt;getMiddleName()." ".$this-&gt;person-&gt;getLlast_name;
        echo '&lt;br&gt;';
    }
}


so it can be used like this

$output = new Output(new Person('ken dan', 'sunico', 'tinio'));
$output-&gt;generate();