Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85804 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71826 invoked from network); 14 Apr 2015 14:33:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2015 14:33:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.217.171 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.217.171 mail-lb0-f171.google.com Received: from [209.85.217.171] ([209.85.217.171:36645] helo=mail-lb0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 16/D2-47925-4352D255 for ; Tue, 14 Apr 2015 10:33:25 -0400 Received: by lbbqq2 with SMTP id qq2so10020493lbb.3 for ; Tue, 14 Apr 2015 07:33:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=xgSfy0vsgOM6cCo5ydGaBZ8B4V/mC2mM4gDVJ+pC1fg=; b=el72xYjXmakWL/vQaKl+bunxpY1+4yo+WX8B2LA397UqIuVsfs1Kf3Z/CBpqjOA2yg l56r2rBv6bHhmcZWGvsMOK9m7wGxj84JNptW3ewegU5p7PDRp1vuTfSYCrPRA7MgucME gc9ZNoCAaPli/knOnAMMpnNmDR0+NaFaszJ362Pr/jLg67/rsCv0esS6tNeSbKKRkl5c yU2v3d7CUBPbWymu18Qm0+U1p9BqhFEHxUsw6UNKWqJavQzTcyoWVuI9rQrt55VICWJR YCQt2Fy9iRtQto5rL+ZC4aJwAL88TTN+Da1/ijwF8+4a4zz4ELmkPHcmbyr1cY4fu0Af 3a+Q== X-Gm-Message-State: ALoCoQmHbwVZzpFQKlRKwkGqTUMR70wdhECKQdxaLzLoMm4vq4Y75iPkeWzyqGz6uduhHVGsQ9s0 MIME-Version: 1.0 X-Received: by 10.112.150.130 with SMTP id ui2mr18932454lbb.116.1429022001884; Tue, 14 Apr 2015 07:33:21 -0700 (PDT) Received: by 10.25.162.146 with HTTP; Tue, 14 Apr 2015 07:33:21 -0700 (PDT) X-Originating-IP: [2.96.92.71] In-Reply-To: References: Date: Tue, 14 Apr 2015 14:33:21 +0000 Message-ID: To: Johannes Ott Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] New RFC draft "static class constructor" From: danack@basereality.com (Dan Ackroyd) Hi Johannes, On 13 April 2015 at 13:37, Johannes Ott wrote: > Hi, > > finally I managed to do my first RFC draft. > > https://wiki.php.net/rfc/static_class_constructor > > I hope I have done everything correct so far and I'm looking forward to > your feedback on it. Here is some feedback then: From the RFC: > - Trigger for =E2=80=9Cmagic=E2=80=9D method call: First call to class, e= ither first call to __construct(...) or first call to any public or protect= ed static method or property of the class I don't think this doesn't cover all cases that it needs to. For example calling unserialze on some data that results in a class that has this static initializer should mean that it would be invoked? Similarly ReflectionClass::newInstanceWithoutConstructor also creates a class in a way that isn't covered in the RFC, but presumably should be. From the RFC. > the static class constructor should be able to throw a catchable Exceptio= n > for user error handling, if it is not possible to initialize. The open is= sue for > me is, what the behavior on recalling the static class constructor afterw= ard is. > There are two possible behaviors I do not know which one I really would p= refer so far. You missed the third and in my opinion correct one; the static initializer would only ever be called once. If the programmer catches the exception and forces the program to continue, that is their own problem. Adding complexity to a language to try to work around programmers ignoring exceptions is not a good idea. I think the RFC needs to be clearer in the specification of the order that static initialization is called in. e.g. class B extends class A. Both A and B have static initialization blocks. When a user calls `new B()` which static initialization block is called first? cheers Dan