Re: coding recommendations
| From: | Stig S. Bakken | Date: | Mon, 27 Jan 2003 09:30:34 +0000 |
| Subject: | Re: coding recommendations | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-12767@lists.php.net to get a copy of this message | ||
On Sun, 2003-01-26 at 14:50, Jan Schneider wrote:
> Zitat von Mika Tuupola <tuupola@appelsiini.net>:
>
> > On Sun, 26 Jan 2003, Krystof Slaby wrote:
> >
> > > 2)
> > > why there's no recommendation for constructor to return error code
> > (pear error)
> > > based on successfullness of initialization ?
> >
> > Constructor can't return anything else than an instance of
> > itself. Or actually it could, but that was considered a bug
> > not a feature. IIRC this behaviour was fixed in PHP 4.3.0.
>
> It still works (PHP 4.3.1-dev):
>
> class Foo {
> function Foo()
> {
> ....
> if ($error) {
> $this = PEAR::raiseError('Foo has bared');
> return;
> }
> }
> }
It is not considered a bug, but an undocumented side-effect that will
change in PHP 5. I would like to discourage everyone from trying to do
this. A better approach is to avoid "failing logic" in the constructor
and do an extra method call that can return an error properly.
- Stig