Re: make new return a reference to existent object
| From: | Jochem Maas | Date: | Mon, 09 May 2005 18:10:45 +0000 |
| Subject: | Re: make new return a reference to existent object | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-214792@lists.php.net to get a copy of this message | ||
Leonardo Pedretti wrote:
I would like (for code cleanliness purposes) to make 'new' return a reference to an already created object under certain circumstances without using a factory, is it possible?not unless you hack the php engine (in which case your code will only work on your custom php build), I'll bet money that none of the php/zend devs feel anything for introducing this kind of 'magic' into engine. IMHO a factory would be a clean method of handling this behaviour and has the benefit that no programmer looking at your code will misinterpret occurances of the 'new' keyword. e.g.: class Test { /* ... */ function __construct() {} function get() {} } // and do: $var = Test::get( /* pass ctor args */ ); // instead of: $var = new Test( /* pass ctor args */ ); ... in this example its only 1 extra char to type when using the factory method and you could turn that around by doing something evil(tm) like: $var = Test::_( /* pass ctor args */ ); // '_' is a function name!!! (ala wordpress-CS) maybe reply to generals describing what you are (trying to) do[ing], I for one am always interested in other people's realworld php5/oo problems/ideas/etc :-) rgds, Jochem ps - I redirected this reply to generals because I didn't really think that it was an internals question (and those guys are busy enough :-)
Thanx