Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85788 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77860 invoked from network); 13 Apr 2015 19:34:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Apr 2015 19:34:14 -0000 X-Host-Fingerprint: 93.193.71.58 p5DC1473A.dip0.t-ipconnect.de Received: from [93.193.71.58] ([93.193.71.58:12824] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/05-41712-53A1C255 for ; Mon, 13 Apr 2015 15:34:13 -0400 Message-ID: <74.05.41712.53A1C255@pb1.pair.com> To: internals@lists.php.net Date: Mon, 13 Apr 2015 21:34:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Posted-By: 93.193.71.58 Subject: Re: New RFC draft "static class constructor" From: mail@deroetzi.de (Johannes Ott) Am 13.04.2015 um 18:48 schrieb Cesar Rodas: > Instead of having a method, why don't we allow body expr to be evaluated as we see things in the Class definition? > > > class foobar > { > static protected $conn = new mysqli('localhost', 'my_user', 'my_password', 'my_db'); > } > > It's cleaner but it breaks compatibility with everything :-( > > -- > César D. Rodas > Open Source developer > +595-983-161124 > PGP: F9ED A265 A3AB C8A1 D145 7368 158A 0336 C707 0AA6 Hello César, you accidently wrote this answer only to me, so I forward this to the mailing list together with my answer. First of all I would not store any resource handle, like a mysql connection you did in your example, directly to a static member. (Will add another point on this to the discussion-section the next days) https://wiki.php.net/rfc/static_class_constructor#discussions Second point is that with your suggested syntax only single methods can be used to initialize the static member. With my proposal you will be able to do more complex initialization algorithms. For example open a config-file with fopen, read the content to a static member and close the config-file again with fclose. Regards -- DerOetzi