re: PHP Typed Properties: Think Twice. VIEW POST


Isn't the first example breaking the Encapsulation principle of OOP? I rarely ever use public properties, they are almost always protected or in some cases private.

I'd put these interfaced properties that you propose in Abstract classes rather than in Interfaces. Makes more sense in my opinion, Interfaces should stay stateless and remain the messaging contract. :)


You can call it however you want but if another object can directly (on properties) change the state of your object, that object is not encapsulated :)


An excerpt from the article:

In the glossary of Design Patterns, Gamma et al., encapsulation is defined as "The result of hiding a representation and implementation in an object..."
So such luminaries as Gamma et al. and the designers of C++ (and Java) are wrong!?
Clearly that there are two definitions of encapsulation, but both valid. It's common for the same word to have different meanings in different communities or contexts. It is not meaningful to say one definition is correct and the other wrong.

code of conduct - report abuse