Skip to content
Advertisement

Tag: visibility

Private property in parent class can be accessed and re-assigned through the instance of child class in PHP but protected one can’t

I am very confused why $produk1->harga = 500; can still make a change (or re-assign the value 500) to private $harga property despite private $harga in class Produk has PRIVATE visibility ? $product1 is an instance of class Komik. $produk1 = new Komik(“Naruto”, “Masashi Kishimoto”, “Shonen Jump”, 30000, 100); And by echo $produk1->harga; it prints out 500 and not an

Advertisement