Reply to Re: [PHP] Re: [PHP-DEV] make new return a reference to existent object

Your name:

Reply:


Posted by Rory Browne on 05/10/05 02:28

I think Leonardo might have a point here. Built-in support for
Singletons could be a nice feature, without the use of static
functions, would be nice. I wouldn't use the 'new' keyword however. I
think something along the lines of existing, or ref

$ref = existing TEST; // which would return an existing instance of
TEST, if one exists, and a new one if it doesn't. ( pretty much like
the singleton code, except no need for singleton code)

I don't think it's anything important, and there are more pressing
matters, to be worked on, I'm sure, but if someone created the code,
and it was secure / bug-free / compliant-with-coding-standards / etc,
I can't see why it couldn't(or shouldn't) be included. When all's said
and done though, it's still just syntactic sugar. It all depends on
how sweet the devs consider it.

On 5/9/05, Jochem Maas <jochem@iamjochem.com> wrote:
> 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация