You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`public` methods and properties are most dangerous for changes, because some outside code may easily rely on them and you can't control what code relies on them. **Modifications in class are dangerous for all users of class.**
1166
+
*`protected` modifier are as dangerous as public, because they are available in scope of any child class. This effectively means that difference between public and protected is only in access mechanism, but encapsulation guarantee remains the same. **Modifications in class are dangerous for all descendant classes.**
1167
+
*`private` modifier guarantees that code is **dangerous to modify only in boundaries of single class** (you are safe for modifications and you won't have [Jenga effect](http://www.urbandictionary.com/define.php?term=Jengaphobia&defid=2494196)).
1168
+
1169
+
Therefore, use `private` by default and `public/protected` when you need to provide access for external classes.
1170
+
1171
+
For more informations you can read the [blog post](http://fabien.potencier.org/pragmatism-over-theory-protected-vs-private.html) on this topic written by [Fabien Potencier](https://github.com/fabpot).
1172
+
1161
1173
**Bad:**
1162
1174
1163
1175
```php
@@ -1849,7 +1861,7 @@ class Robot implements Employee
1849
1861
1850
1862
**Good:**
1851
1863
1852
-
Not every worker is an employee, but every employee is an worker.
1864
+
Not every worker is an employee, but every employee is a worker.
1853
1865
1854
1866
```php
1855
1867
interface Workable
@@ -2087,8 +2099,16 @@ function showList(array $employees): void
0 commit comments