DEV Community

Discussion on: How you can reduce usage of getter methods in your code

Collapse
 
biros profile image
Boris Jamot ✊ /

BTW, PHP allows asking private attributes inside a class of same object.

Did you mean "inside an object of same class" ?

class A {
    // @var int
    private $p;

    public function equals(A $a)
    {
        return $this->p === $a->p;
    }
}

Here we can access private property $a->p because $this and $a are of the same class.

I didn't know, thanks for that!