Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to inherit a class php


I think the best way for beginners to understand inheritance is through a real example so here is a simple example I can gave to you 

<?php

class Person
{
    public $name;
    protected $age;
    private $phone;

    public function talk(){
        //Do stuff here
    }

    protected function walk(){
        //Do stuff here
    }

    private function swim(){
        //Do stuff here
    }
}

class Tom extends Person
{
    /*Since Tom class extends Person class this means 
        that class Tom is a child class and class person is 
        the parent class and child class will inherit all public 
        and protected members(properties and methods) from
        the parent class*/

     /*So class Tom will have these properties and methods*/

     //public $name;
     //protected $age;
     //public function talk(){}
     //protected function walk(){}

     //but it will not inherit the private members 
     //this is all what Object inheritance means
}

Comment

PREVIOUS NEXT
Code Example
Php :: aes php 
Php :: php ternary operators 
Php :: with message in laravel 
Php :: Laravel Excel numbers formatted as text still appearing as number 
Php :: the uploaded file exceeds the upload_max_filesize in laravel 
Php :: twig or 
Php :: str_ireplace 
Php :: with in laravel 
Php :: php force array keys trim 
Php :: laravel passport get tokenId 
Php :: php array_map() 
Php :: php code to generate strong password 
Php :: php date set utc 
Php :: ISO 8601 php 
Php :: remove certain haracters from a string php 
Php :: how to use join in laravel 5.4 
Php :: laravel collection concat 
Php :: insert date of birth on the database using php 
Php :: laravel get latest 
Php :: laravel hasmany 
Php :: remove a specific element from an array php 
Php :: laravel wherenotin 
Php :: create a new project from cli laravel 
Php :: get ip address of client php 
Php :: laravel collection isempty 
Php :: change the date format in laravel view page 
Php :: check if session is started 
Php :: laravel generate unique db token 
Php :: check if string contains substring php 8 
Php :: php artisan route cache 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =