Re: PHP - Does it ignore return val from constructors?

From: Chung Leong (chernyshevsky_at_hotmail.com)
Date: 02/26/05


Date: Sat, 26 Feb 2005 00:12:14 -0500


"thecrow" <carltonbrown@hotmail.com> wrote in message
news:1109294863.754779.98710@g14g2000cwa.googlegroups.com...
> Thank you for the explanation.
>
> That leaves me with the problem, if I fail the constructor by setting
> $this to false, how do I get the error information without echoing it?
>
> I guess I can go search on that, but if anyone has any commonly used
> ideas I would appreciate it.
>

That was just a stupid PHP 4 trick. Don't use it. It doesn't work in PHP 5.

Constructors are meant for initializing an object. They are not supposed to
fail. The only reasonable way to handle a failure in a constructor is
through exception handling, which doesn't exist in PHP 4. As others have
suggested, put the code that could potentially fail in a separate function.



Relevant Pages

  • Re: Constructor fail?
    ... The ability to fail a constructor is often done by throwing an exception in ... the constructor. ... this is not good because AFAIK it can result in ... > I want to create a class with a constructor which can fail (for example ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: OOP / language design question
    ... constructor will cause a program to fail spectacular. ... it can do that because of static typing - in fact it will fail on a lot ... more of occasions with a compilation error. ...
    (comp.lang.python)
  • Re: Unsave code Fail
    ... Init must be a function, since it returns a boolean value. ... fail could be called only from within a constructor. ... boolean value (in Delphi they always return a pointer to the object). ...
    (comp.lang.pascal.delphi.misc)
  • Re: Constructor inheritance (or lack thereof)
    ... > declared constructor taking an object parameter rather than a base ... people working at the application level to be inheriting our base classes. ... expecting a follow-up an initialize method as an ... so define the ctor and fail to follow up with base. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: server partitioning
    ... do not want me to fail. ... I then proposed to put php and MySQL on a Windows server. ... I was asked to move the content of a website ...
    (alt.os.linux.suse)