Reply to Re: instantiating an object fails (design patterns)

Your name:

Reply:


Posted by Colin McKinnon on 09/16/05 14:20

www.douglassdavis.com wrote:

>
> lets say i have a class
>
>
> class Thing
> {
> function __construct($string)
> {
> // initialize by string
> }
> }
>
>
> Let's say an invalid string is passed to construct it. What is the
> appropriate way to handle this? I know in Java I would probably throw
> an exception, but I don't know how much people really use exceptions in
> PHP right now. So, I don't want to depend on it.
>

This seems an odd thing to say.

> What would be the appropriate way to handle this type of situation? I
> was thinking of two options
>
> 1. A ThingFactory that just returns null if the Thing couldn't be
> instantiated.
>
> 2. Remove the constructor and just have an initThing($string) method
> that returns false when something goes wrong.
>
> What would be appropriate here?
>

Its up to you. You could look at how PEAR handles this (which is fairly
*correct* but you then get all the disadvantages of using PEAR). Personaly,
I usually use trigger_error() and my own error handler although this isn't
a very OO way of doing things.

C.

[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

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