Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84613 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15363 invoked from network); 12 Mar 2015 08:24:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2015 08:24:25 -0000 Authentication-Results: pb1.pair.com header.from=indeyets@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=indeyets@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.169 as permitted sender) X-PHP-List-Original-Sender: indeyets@gmail.com X-Host-Fingerprint: 209.85.212.169 mail-wi0-f169.google.com Received: from [209.85.212.169] ([209.85.212.169:37942] helo=mail-wi0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 92/48-64353-73D41055 for ; Thu, 12 Mar 2015 03:24:23 -0500 Received: by widex7 with SMTP id ex7so44797263wid.3 for ; Thu, 12 Mar 2015 01:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=rAlOmYAc17aAH75jz2ZrwtEPx0642CoNBesWyHJMKVY=; b=EIq2U7JwlK2zYaoutsflrMWFM4XznLQT3zRFc8hsNKK9NpVtb836p9eI7tC2FvkkTh MO8OuGjSweGN7eQ+RVmmKUUZSPyxH2ybGqTfMzmw1xacNSejV1mJTYTHpngR/VYW+xs6 HSljbURVBUpYH08zZbwFIbF+qYFdUU9q7/7GaKGnjb1odM5pQTm37bJn7LYOQVEyXN/F swv1x8oVPOxfD7uKFAPF5zqhBYXS1w1tGd+ryFyL8lu5knq4k9XAezUOyOi0cgXe7W8p ZpuAMM60KjuUNAUM4rkZc8E3eB2rUD3jCMDncGs0ssuCcPAOCdgLNUgP703QeHzc2SAM n6uA== X-Received: by 10.194.60.104 with SMTP id g8mr83231956wjr.96.1426148660913; Thu, 12 Mar 2015 01:24:20 -0700 (PDT) Received: from [10.0.1.8] ([91.219.26.208]) by mx.google.com with ESMTPSA id vq9sm8936601wjc.6.2015.03.12.01.24.19 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Mar 2015 01:24:20 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: <6D.2C.32765.10EC0055@pb1.pair.com> Date: Thu, 12 Mar 2015 11:24:18 +0300 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <6D.2C.32765.10EC0055@pb1.pair.com> To: Johannes Ott X-Mailer: Apple Mail (2.2070.6) Subject: Re: [PHP-DEV] static constructor From: indeyets@gmail.com (Alexey Zakhlestin) > On 12 Mar 2015, at 02:21, Johannes Ott wrote: >=20 > 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. >=20 > 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. >=20 > I think about two different possible syntax to realize that purpose: >=20 > Version 1 (similar to Java): >=20 > class A { > private static $var; >=20 > static { > //Do some code here to initialize self::$var; > } >=20 > } >=20 > Version 2 (a new magic method): >=20 > class B { > private static $var; >=20 > private static function __static() { > //Do some code here to initialize self::$var; > } > } >=20 > My prefered code would be version 2 at the moment. >=20 > Looking forward to your feedback, What about inheritance? I think dynamic class-constructor would make much more sense. A function which can analyse real class and do initialisation. class A { protected static function __class_construct() { echo get_called_class().=E2=80=9D class is defined\n"; } } class B extends A { } #### output #### A class is defined B class is defined --=20 Alexey Zakhlestin https://github.com/indeyets PGP key: http://indeyets.ru/alexey.zakhlestin.pgp.asc