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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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 Mar 29 09:01:28 2024 UTC