Answers for "how to access private and protected members in php"

PHP
0

how to access private and protected members in php

<?php

class GrandPa
{
    protected $name = 'Mark Henry';
}

class Daddy extends GrandPa
{
    function displayGrandPaName()
    {
        return $this->name;
    }

}

$daddy = new Daddy;
echo $daddy->displayGrandPaName(); // Prints 'Mark Henry'

$outsiderWantstoKnowGrandpasName = new GrandPa;
echo $outsiderWantstoKnowGrandpasName->name; // Results in a Fatal Error
Posted by: Guest on December-23-2020

Code answers related to "how to access private and protected members in php"

Browse Popular Code Answers by Language