Private Protected Php Code Example


Example: 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

Comments

Popular posts from this blog

530 Valid Hostname Is Expected When Setting Up IIS 10 For Multiple Sites

C Perror Example

Converting A String To Int In Groovy