There are 3 types of access modifiers.
public : public property or method can be accessed Form anywhere (This is by default)
protected : protected proerty can be accessed With in the class & child class which extending parent class
private : "private" property or method can be access ONLY in the class.
NOTE: if you want to Access a "Private Property" Which is only accessible inside the class, then for that,
first, you have to create a "Public function", Then access that "Public function" after creating an object.
<?php
class AccessModifiers
{
public $name;
protected $color;
private $height;
function get_protected($color)
{
return $this->color = $color;
}
}
$a_Obj = new AccessModifiers();
echo $a_Obj->name = 'mango. <br>';
echo $a_Obj->get_protected("red");
?>
public : public property or method can be accessed Form anywhere (This is by default)
protected : protected proerty can be accessed With in the class & child class which extending parent class
private : "private" property or method can be access ONLY in the class.
NOTE: if you want to Access a "Private Property" Which is only accessible inside the class, then for that,
first, you have to create a "Public function", Then access that "Public function" after creating an object.
<?php
class AccessModifiers
{
public $name;
protected $color;
private $height;
function get_protected($color)
{
return $this->color = $color;
}
}
$a_Obj = new AccessModifiers();
echo $a_Obj->name = 'mango. <br>';
echo $a_Obj->get_protected("red");
?>
0 comments:
Post a Comment