SHARE
TWEET

Object Oriented PHP Part-4(Access Modifier)

bappy7706 May 31st, 2020 (edited) 841 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport"
  6.           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8.     <title>Document</title>
  9. </head>
  10. <body>
  11. <h1 style="text-align: center;color: maroon;font-weight: bold; font-family: 'Mongolian Baiti'"> Object Oriented PHP Part-4(Access Modifier)</h1>
  12. <br>
  13.  
  14.  
  15. /*
  16. public - Access from anywhere
  17. private- only accesss from own class
  18. protected - access from own class and subclass
  19.  
  20. */
  21.  
  22. <?php
  23.  
  24. class Test{
  25.  
  26.     public $x =200;
  27.     protected $y =400;
  28.     public $z =600;
  29.  
  30.     private $bp =90;
  31.  
  32.     protected $xc =5235;
  33.  
  34.  
  35.    // public function getBp()
  36.          private function getBp()
  37.     {
  38.  
  39.         return $this->bp;
  40.  
  41.     }
  42.  
  43.  
  44.     public function gettt()
  45.     {
  46.  
  47.         return $this->getBp();
  48.  
  49.     }
  50.  
  51. }
  52.  
  53.  
  54. class CTest extends Test
  55. {
  56.  
  57.   public function getX()
  58.   {
  59.  
  60.       return $this->xc;
  61.   }
  62.   public function getY()
  63.   {
  64.       return $this->y;
  65.  
  66.   }
  67.  
  68. }
  69.  
  70.  
  71. $obj=new CTest;
  72. echo $obj->getX();
  73. echo "<br/>";
  74.  
  75.  
  76. echo (new CTest)->getY();
  77.  
  78. //echo (new Test)->z;
  79.  
  80. /*
  81. $ob=new Test;
  82. echo $ob->gettt();
  83. echo  "<br/>";
  84.  
  85. $ob->x=412414;    //modifying x
  86. echo $ob->x;
  87.  
  88. */
  89.  
  90. ?>
  91.  
  92. </body>
  93. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top