Skip to main content

Posts

Showing posts with the label Access modifier

Access modifier in php

Access modifier in php Restricting access to properties PUBLIC PRIVATE PROTECTED Those class properties and class methods which are set to be PUBLIC is accessed from any where in PHP script.I Access: Every where Those Class properties and class methods which are set to be PRIVATE can only be access with in the class.i.e Only the same class can access the property. Access: This class only Those class properties and class methods which are set to be PROTECTED can only be accessed in side a class and from its child class.i.e only the same class and classes derived from that class can access the property Access: This Class and sub class. public $height; protected $social_insurance; private $pin_number; $abc = new User(); /* Since $pin_number was declared private, this line of code will generate an error. Try it out! */ echo "Tell me private stuff: ".$abc->pin_number; /* Since $pin_number was declared protected, this line of code will genera...