Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88497 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32964 invoked from network); 25 Sep 2015 15:13:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Sep 2015 15:13:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=codekestrel@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=codekestrel@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: codekestrel@googlemail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:36286] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5F/94-31991-CA465065 for ; Fri, 25 Sep 2015 11:13:48 -0400 Received: by wicgb1 with SMTP id gb1so24890299wic.1 for ; Fri, 25 Sep 2015 08:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=L1Xs5MZgQhhz/WRLojYjr+LFOVg64LQsce70XOt608s=; b=UHdUZdSWJBZTXVfjdX7lEBfaKBislURHlTuLNjN3YCR2vi1jjPj+l9ZZ4dWQFxAPUN 0cWPeQ23l8k1+PywY4auhFOoJVVCnPbpxyK+sc6HSzA/MEU+vr0cGkQLC6d/2ZVLVNn5 aK1R01T+VeXD8TJgwRdMj8D7lZ0I7VxIhCnT7/pQAij9YzuC3AcKE2p7MNNVLCa2y6ho ZINJ7yt8Sf7JZM1E4sGR55XYciTp9IYcUzgTywT7GGYT+DYVq+6WKIPdD5lYYVzRiFDx eJbItQvLgpVXiQamfnhwM4ss7GzvEczt7VVB22UfcxuzffYzidskmDtPtwha10l8kQN2 Wb0g== MIME-Version: 1.0 X-Received: by 10.194.19.169 with SMTP id g9mr6721215wje.64.1443194025108; Fri, 25 Sep 2015 08:13:45 -0700 (PDT) Received: by 10.27.104.197 with HTTP; Fri, 25 Sep 2015 08:13:44 -0700 (PDT) Received: by 10.27.104.197 with HTTP; Fri, 25 Sep 2015 08:13:44 -0700 (PDT) In-Reply-To: <1443182942.15520.13.camel@kuechenschabe> References: <1443182942.15520.13.camel@kuechenschabe> Date: Fri, 25 Sep 2015 16:13:44 +0100 Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=047d7b3a9cbc356c9e052093cb8c Subject: Re: [PHP-DEV] Implementing Generics, and none scalar default properties. From: codekestrel@googlemail.com (Dominic Grostate) --047d7b3a9cbc356c9e052093cb8c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, I see what you mean with static properties, that would be more difficult. I can answer on non-static however. * When will $p2 be initialized, which properties can it access? - On class instantiation. It won't have access to $this, because the object won't have been created yet. It will have access to the same entities as a static method. * In B's constructor we're overwriting $p1, so $p2 will be initialized with the wrong value. - It won't have access to $this. In effect they are pre-constructor assignments, just like any other property. Concerning reassignment on constructor leading to wasted code, I can only place faith in the effectiveness of the user to override those properties to NULL. Anyway sorry about the mixed post. I've mainly been working on implementing generics, so I have a separate thread somewhere for that. Dominic On 25 Sep 2015 1:09 pm, "Johannes Schl=C3=BCter" w= rote: > Hi, > > Would be good to split complete different subjects to different threads > anyways: > > On Wed, 2015-09-23 at 15:53 +0100, Dominic Grostate wrote: > > the > > ability to set default values of properties to instances of objects or > > calls to static methods or functions (expressions in general). > > This causes questions on the order of execution and leads to waste of > CPU time in case the constructor overrides the default value while not > bringing much benefit over initialization in the constructor. It also is > complicated regarding exceptions being thrown. > > Take the following code: > > > foo(); > > class A { > protected $p1 =3D new Something(); > private $p2 =3D new SomethingElse($this->p1, $this->p3); > private $p3 =3D new Something(); > private static $s1 =3D new StaticSomething(); > > public function __construct() {} > } > > bar(); > > class B extends A { > private $p4 =3D new Something(); > > public function __construct() { > parent::__construct(); > $this->p1 =3D new Whatever(); > } > } > > baz(); > > try { > $b =3D new B(); > } catch (Exception $e) { > } > ?> > > Some Questions: > > * Where, relative to foo(), bar() and baz() will StaticSomething's > constructor be called? How do you capture exceptions from there? > * When will $p2 be initialized, which properties can it access? > (Only the ones initialized before? None?) > * In B's constructor we're overwriting $p1, so $p2 will be > initialized with the wrong value. > > I'm sure there are more questions ... doing this i the constructor makes > things clear and explicit with about the same amount of code to write. > > johannes > > --047d7b3a9cbc356c9e052093cb8c--