Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84609 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94750 invoked from network); 12 Mar 2015 04:17:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2015 04:17:34 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.182 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.223.182 mail-ie0-f182.google.com Received: from [209.85.223.182] ([209.85.223.182:36679] helo=mail-ie0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B7/65-64353-C5311055 for ; Wed, 11 Mar 2015 23:17:33 -0500 Received: by iegc3 with SMTP id c3so16030874ieg.3 for ; Wed, 11 Mar 2015 21:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=4N5VTK/ChVjC/tEmxocg0fkGU+i4QcdsnDsSNkpqv+s=; b=PULtjy4jb4J6I+S0ejzF3NSfBd2qJb4ZUCn3LgcEyiLIB0/pZzzYmVdraBOICHX2dz Vaplx8Nw9M7BIFcRFP5rZ04Fiy/YXV7jUgN6K+Lqi/rK2fyxKv+8yLqP2lOXccPpQ9lH YDDQOSCgGDEiTGv5NLZu5SMvxBQF/0zOWPNIxgHdPPo8g25EZGBj9IqWIl+Zq4f8W6ZT sKoOX9guHhrTUT8gQ7LOJYWS7RrpFp9tqmMph++vjQITc9WkP+2Vh1oQr2YCNF/lwphs 6IuYAjcSgqHDk/PXXSxONPJ3totLbUUsLkopK4v6otB+tebN1YUJW6nN94vQa6IL5Gl2 fbKQ== MIME-Version: 1.0 X-Received: by 10.202.76.207 with SMTP id z198mr6976068oia.56.1426133850071; Wed, 11 Mar 2015 21:17:30 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.76.90.74 with HTTP; Wed, 11 Mar 2015 21:17:30 -0700 (PDT) In-Reply-To: <5500D967.5040800@gmail.com> References: <6D.2C.32765.10EC0055@pb1.pair.com> <5500D967.5040800@gmail.com> Date: Wed, 11 Mar 2015 22:17:30 -0600 X-Google-Sender-Auth: VHDTDDVpp4xwf2lw2x-1da6V5Nw Message-ID: To: Rowan Collins Cc: internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] static constructor From: levim@php.net (Levi Morrison) On Wed, Mar 11, 2015 at 6:10 PM, Rowan Collins wrote: > On 11/03/2015 23:21, Johannes Ott wrote: >> >> So now I want to do my first own proposal for a new function in PHP and >> I hope doing it right with starting a discussion here first. >> >> The purpose of this suggestion is to introduce a static constructor, >> which is called before the first call to class either static or >> non-static to initialize some static properties which are needed by the >> class. > > > Can you give an example use case for when this would be useful? I'm > struggling to think of one for which there isn't already an established > coding pattern... Notably, user-land enums. You don't want public constructors because you don't want it instantiated except for each enum property. You also need it to run on class creation, not afterwards. I think we'd be better off adding language-level enums than static constructors though.