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 Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or 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

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: Fri Apr 19 01:01:28 2024 UTC