Req #60098 [Opn]: Static constructors, or static intializers

From: Date: Wed, 27 May 2015 22:35:51 +0000
Subject: Req #60098 [Opn]: Static constructors, or static intializers
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192944@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60098&edit=1 ID: 60098 Updated by: cmb@php.net Reported by: syntaqx at gmail dot com Summary: Static constructors, or static intializers Status: Open Type: Feature/Change Request Package: SPL related Operating System: All -PHP Version: 5.4.0beta1 +PHP Version: * Block user comment: N Private report: N New Comment: FWIW, there is a respective RFC in draft state: <https://wiki.php.net/rfc/static_class_constructor>. Previous Comments: ------------------------------------------------------------------------ [2013-05-03 19:31:32] mkutschker-php at yahoo dot com I think that a magic method named __init() would be a PHP way to go. ------------------------------------------------------------------------ [2011-10-27 14:56:38] 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? ------------------------------------------------------------------------ [2011-10-24 16:30:02] dagguh at gmail dot com You mean something like Static Initialization Blocks from Java? Yeah, I'd like to see them too. http://download.oracle.com/javase/tutorial/java/javaOO/initial.html ------------------------------------------------------------------------ [2011-10-19 17:48:18] syntaqx at gmail dot com Description: ------------ 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 successful. 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 around. Thanks a bunch for taking the time to read my request, I'm excited to hear what you think :) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60098&edit=1

« previous php.bugs (#192944) next »