|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60098 Static constructors, or static intializers
Submitted: 2011-10-19 17:48 UTC Modified: 2018-08-20 13:25 UTC
Avg. Score:4.2 ± 0.7
Reproduced:6 of 7 (85.7%)
Same Version:3 (50.0%)
Same OS:4 (66.7%)
From: syntaqx at gmail dot com Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: * 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.
Block user comment
Status: Assign to:
Bug Type:
From: syntaqx at gmail dot com
New email:
PHP Version: OS:


 [2011-10-19 17:48 UTC] syntaqx at gmail dot com
I've noticed a fairly large trend in a lot of php frameworks, as well as in my 
own code, and I was curious about whether this is planned, the reasons as to why 
it might not be, or if it has even been brought up.

I've tried to find any other requests about this, but haven't been very 

Basically, my request is this:
When a class comes into existence (whether the code is in the file you're 
currently in, or you're including it), a static constructor (a common method for 
it is "::init") is called. This is called only once, the first time the class 
exists, and would act as a protected method (allowing parent-child objects to 
call it incase of a class reset?).

This would be pretty awesome, but I don't know if it's practical, or what all 
your thoughts might have been as I'm sure plenty of you have seen it floating 

Thanks a bunch for taking the time to read my request, I'm excited to hear what 
you think :)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-24 16:30 UTC] dagguh at gmail dot com
You mean something like Static Initialization Blocks from Java? Yeah, I'd like to 
see them too.
 [2011-10-27 14:56 UTC] syntaq at gmail dot com
That seems to be what I'm requesting. Does that seem like something that could be 
implemented into PHP fairly easily?
 [2013-05-03 19:31 UTC] mkutschker-php at yahoo dot com
I think that a magic method named __init() would be a PHP way to go.
 [2015-05-27 22:35 UTC]
-PHP Version: 5.4.0beta1 +PHP Version: *
 [2015-05-27 22:35 UTC]
FWIW, there is a respective RFC in draft state:
 [2018-08-20 13:25 UTC]
-Status: Open +Status: Suspended -Package: SPL related +Package: Scripting Engine problem
 [2018-08-20 13:25 UTC]
It seems that the “Static Class Constructor” RFC is abandoned, but
this feature request certainly needs the RFC process[1].  If
anybody is still interested in having this feature, please proceed
with this or another RFC.  For the time being, I'm suspending this

[1] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Aug 03 08:01:25 2021 UTC