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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: stefan dot p at noos dot fr
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Mon Dec 30 14:01:28 2024 UTC