note 112390 added to reflectionclass.newinstancewithoutconstructor
| From: | tomatrdotje | Date: | Tue, 11 Jun 2013 09:53:02 +0000 |
| Subject: | note 112390 added to reflectionclass.newinstancewithoutconstructor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195126@lists.php.net to get a copy of this message | ||
It should be made clear that from an OOP theory perspective the use of this method is very bad
practice in the same manner as goto, eval and singletons. If you find a need to use it in production
code you're almost certainly doing something wrong somewhere. It may occasionally be useful for
debugging, but even then hints at poor initial code.
The problem? It breaks encapsulation. An object can exist in the application but may not be able to
fulfill its responsibility because it's missing dependencies. The use of this method makes it
possible for an incomplete object to exist in the system; the object can exist in a state that its
author never intended. This is bad because it will cause unexpected things to happen! A fundamental
principle in OOP is that objects are in complete control of their state, the use of this method
prevents that guarantee.
n.b. The annotation based "dependency injection" listed below is not a solution or valid
use-case for this either because it breaks encapsulation (Among other things!) and the class being
constructed needs to know of the container by providing annotations.
----
Server IP: 69.147.83.199
Probable Submitter: 109.232.62.156
----
Manual Page -- http://php.net/manual/en/reflectionclass.newinstancewithoutconstructor.php
Edit -- https://master.php.net/note/edit/112390
Del: integrated -- https://master.php.net/note/delete/112390/integrated
Del: useless -- https://master.php.net/note/delete/112390/useless
Del: bad code -- https://master.php.net/note/delete/112390/bad+code
Del: spam -- https://master.php.net/note/delete/112390/spam
Del: non-english -- https://master.php.net/note/delete/112390/non-english
Del: in docs -- https://master.php.net/note/delete/112390/in+docs
Del: other reasons-- https://master.php.net/note/delete/112390
Reject -- https://master.php.net/note/reject/112390
Search -- https://master.php.net/manage/user-notes.php