☜
☞
Access Modifiers
In the access modifiers AccessModified, we created three access modifiers namely private, protected and public. The access differently depending on which it is used in the class.
Private: This is only called within a class.
Protect: Is call inside a class and the class that extends it.
Public: Call anywhere the class.
For a private and protected we called write functions to called them and we called them outside of the class using the echo echo $accessModified->name(); and echo $accessModified->age();. For the public we call it from outside the class and it is fine with it.
<?php
class AccessModifier{
private $name = 'Lokang';
protected $age = 40;
public $color = "black";
public function age(){
return $this->age;
}
public function name(){
return $this->name;
}
}
$accessModifier = new AccessModifier();
echo $accessModifier->name();
echo '<br>';
echo $accessModifier->age();
echo '<br>';
echo $accessModifier->color;
☜
☞