Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108733 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93209 invoked from network); 24 Feb 2020 05:09:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2020 05:09:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B293D1804E0 for ; Sun, 23 Feb 2020 19:26:33 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 23 Feb 2020 19:26:32 -0800 (PST) Received: by mail-io1-f41.google.com with SMTP id d15so8793093iog.3 for ; Sun, 23 Feb 2020 19:26:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eAoO0Rro84URvSEcYnt2MYxHi6VWAB0C6dXuhLbPkXI=; b=WFLPPaS3NzxUs6FykKdOORycythlu/UKo6ADv8yH1vGzsA+Jehlev5XrcdsW9ZxE7X Po0Jq/3/wDLxTjxprMnKpJ5oUZbfKCkMbIgGo7LojGnzjCDZWvctBGjs7aznEcvMwXFL pRlfHKXE5nmFL985drkGaG4pLS7KmELDRG0Y+C34lMvWDR6VO3IPxv1JonRp4OYkGSEh bKvTzsKZvR+gUBjRXSZrirqA11lt3To/1Sy1oYUZ7YJ0sMkPpWcJqbPPfKXh0MM/rq/X m6A0eqWxxvt/Qt0QiI33Pnz8eMp4vXO5Wo/DFfQAgoCltsZYCr9WNH7DUAFwW2MvW5T4 X9EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eAoO0Rro84URvSEcYnt2MYxHi6VWAB0C6dXuhLbPkXI=; b=hxod+GS/+Cs4wyOWJFndG+GjQsmdhSMk/Orzv+osyZon0u7usFi0N/9y0DGVh9H3WW Ti0Kn6rJ5YzChIqZxT1S4ACl6mTho95duYHnliZXHR1pw2r78qsVGQQ4wanJT6RIWPwC DfkC0ov0n0phrSHjnQk9I6Y3jEXh8GAdecQKFsAk2rU1iqTjP13+rBOg4YKRqSIxNX/U X1ivssZV2EfWenbyZkQyTWhOdVCB3galmBg7FscuZNHUStUo6aa37sweOjh6sAMa20Jv MCu+hRJd99e9GeL46Eq0uaRSIr8YzSze0KJ9W9mwvpB766vdFwG6gGhDFl6fklRqcor+ rv2A== X-Gm-Message-State: APjAAAULH0VOgENID/sqhmlpgaPaHc3nCRphuXudECRyeCZQoK3Nk9zA 0BiicY6jVUSxMTPmWoBlP005i5SKGtW1yv8W43tCQU3QEdM= X-Google-Smtp-Source: APXvYqxyV82FZ49F4nQWVcBb5OnEacf7GeR86dElWMfMgasYqs1UIPAVFuzeTJsVoWopLXV8W1y/xWCeS2Lfiu1DEVM= X-Received: by 2002:a6b:dd11:: with SMTP id f17mr41818356ioc.35.1582514791962; Sun, 23 Feb 2020 19:26:31 -0800 (PST) MIME-Version: 1.0 References: <8545d15e-ddd5-42be-8405-09697a077234@www.fastmail.com> <4d9688fe-cc57-44af-903e-05f4cbb1bbcc@www.fastmail.com> <452D962A-C588-4F04-B000-479EBEA9B9DB@newclarity.net> <9ebc648c-39d1-45b1-9f3d-9a799c6dec93@www.fastmail.com> In-Reply-To: <9ebc648c-39d1-45b1-9f3d-9a799c6dec93@www.fastmail.com> Date: Mon, 24 Feb 2020 04:26:19 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000006dd44059f49f0b3" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties From: ocramius@gmail.com (Marco Pivetta) --00000000000006dd44059f49f0b3 Content-Type: text/plain; charset="UTF-8" Hey Larry, On Sun, Feb 23, 2020, 18:06 Larry Garfield wrote: > > It does not. > > 1) Race condition if I assume that a public write-once property is a > materialized value, but access it before it gets materialized. > This is alrey true for any public typed properties without default values, and why static analysis tools pick up missing initialisation since ages. > 2) Race condition if internal non-constructor code wants to set the value, > but some external routine has set it first. > Internal ctors are part of the category above: tools like psalm pick this up as well. > 3) Cloning creates an interesting and complicated case of both of the > above. Does a cloned object start with its write-once bits reset or no? > There's problems both ways. > Not a problem: we seem to be making a problem out of the pattern used in current PSR-7 implementations, which is following: final class Foo { public function withBar($bar):self { $instance = clone $this; $instance->foo = $foo; return $instance; } } The solution is trivial: don't use cloning: final class Foo { public function withBar($bar):self { $instance = new self(); $instance->foo = $foo; // more assignments here - unavoidable return $instance; } } --00000000000006dd44059f49f0b3--