Tsallaka zuwa abun ciki
Justice Tech School

public, protected, private

public is open, protected is for the class and children, private is for the class only. Use getters to expose values.

Example
class A {
    private $secret = 1;
    public function get() { return $this->secret; }
}
$a = new A();
echo $a->get(), "\n";
try { echo $a->secret; } catch (Error $e) { echo "blocked"; }

Result

1
blocked

Exercise

Class only.

 $secret;

Quiz Test

Who can read a private property?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.