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

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable