php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #9253 Class constructors can't return values
Submitted: 2001-02-14 05:23 UTC Modified: 2001-02-14 09:44 UTC
From: stefan dot p at noos dot fr Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.0.4pl1 OS: All
Private report: No CVE-ID: None
 [2001-02-14 05:23 UTC] stefan dot p at noos dot fr
Class constructors can't abort instance creation, for example by returning false...
This leads to a lot of "if (! $newobj->status)" crap.
Why is that ? I found a message on the PHP3 mailing list about this, but it's still not there.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-14 09:44 UTC] andre@php.net
class constructors are never supposed to return anything,
they are simple the fist method called after an object has 

<hack>
anyway if you *really* want to return false just kill the
object itself from within the constructor  (to be sure take
the last line)
using
unset($this)
or
$this=FALSE
or
$this=NULL
</hack>

bogusifying

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC