php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62859 Give __construct() the respect it deserves
Submitted: 2012-08-18 19:48 UTC Modified: 2012-08-20 01:32 UTC
From: michaelduff2 at yahoo dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: Irrelevant OS:
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michaelduff2 at yahoo dot com
New email:
PHP Version: OS:

 

 [2012-08-18 19:48 UTC] michaelduff2 at yahoo dot com
Description:
------------
Here's a PHP6 -- or PHP7 ;) request for you; many will scream NOOOOoooooooo, but hear me out:

Make it possible to return an object from __construct().

Yeah, I said it. Sounds crazy, but this would make factories more abstract, and enables all sorts of magic without user code being any wiser (unless they Reflect upon it, I suppose.)

For type safety, the object returned should probably be an instanceof __CLASS__.

If no return() exists, then normal 'new' semantics would apply.

Discuss.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-20 01:32 UTC] aharvey@php.net
Given that you can already implement factories perfectly well via static methods, I can't think of any use for this that doesn't end in making code less clear.

If you want a discussion, write an RFC and post it to Internals, but I can't see this getting up.
 [2012-08-20 01:32 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 09:01:34 2025 UTC