Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
0 votes
1 answer
743 views

why can't I access a protected method from a private method if the protected ones are inherited by the subclasses?

I do not understand this particular case or what Alexander says. class instance is not the same as class? As already Alexander Larikov said that you can't access protected methods from class instance ...
user avatar
1 vote
2 answers
2k views

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 ? $...
didaen's user avatar
  • 48
3 votes
2 answers
3k views

Visibility of __construct

If I have: abstract class AbstractSingleton { protected static $instance; public static function & getInstance() { if(null === static::$instance) static::$instance = new ...
Virus721's user avatar
  • 8,193
0 votes
5 answers
170 views

PHP5 member visibility

Could someone explain me, why is it possible to do the following in PHP, but, for example, not in C# or Java: Class A { protected $a = 'Howdy!'; } Class B extends A { public function howdy() ...
Yippie-Ki-Yay's user avatar
0 votes
2 answers
858 views

How can I protect a class property from extending classes in PHP?

Is it possible to do something like this: class foo { private $private = 'A'; } class bar extends foo { echo $this->private; } bar returns null... I'd really like it if the variable $...
James Thompson's user avatar
6 votes
5 answers
2k views

Is visibility in PHP classes important, and why?

As you know, PHP class has private, public and protected keywords. I just started to write classes and I wonder what are the advantages of class visibility in PHP5. And of course also disadvantages.....
kuzey beytar's user avatar
  • 3,187
23 votes
3 answers
22k views

Strange behavior when overriding private methods

Consider the following piece of code: class foo { private function m() { echo 'foo->m() '; } public function call() { $this->m(); } } class bar extends foo { ...
NullUserException's user avatar