Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108736 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21188 invoked from network); 24 Feb 2020 15:38:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2020 15:38:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7C5D01804D5 for ; Mon, 24 Feb 2020 05:55:34 -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,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-il1-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (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 ; Mon, 24 Feb 2020 05:55:33 -0800 (PST) Received: by mail-il1-f182.google.com with SMTP id b15so7767164iln.3 for ; Mon, 24 Feb 2020 05:55:33 -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; bh=zU/TTWhGmJanghBEhraVfqYD4z74hJ2HifqriEHE7oI=; b=DXGG+BEscyrJxbg86feYgRXLLk/IJN/0vyuDjLQaTP7TOzYhl87kmy/0Q1BfE3ABMK lAeUtFCesFrL3PjUMHPR+3ko9Fwh7gjaPWJxlZO2VIxWMo9A0a1YPNs+POPyK2/Fu3DH 9TrD40sZ0qo4ovxG8ETeINR/sw86TsZbY66Cm9Vt9NsEfXfYvpil0S8URVVXXlmiWgHR ScvQnmWwkLPWvfVTZALLZq9M5Not9/oCIo4QVYYHcUnuTlNkP0BXnGpxWoy+7eVwNMuK kV+Sn7uhrVwNZ15LkoAf5dqwRgt80bA9k2NUJp4BYfm1l84kySE1XxwCnh4iAhNu0cF4 M86Q== 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; bh=zU/TTWhGmJanghBEhraVfqYD4z74hJ2HifqriEHE7oI=; b=lLtTG/bJlZH5hcbDf7h2XhJbZ3OOWu42yJ0TlBs2Y7JXFMlKMX75X+KVR4EEFxYlcR PhhR4vQnWbXcPFOa/XgC7h0eZISdJKuYFkGP5LBtY5NcW7j1O/MtHeRXi1KfsUjWAUzp 9Ko/NPxC3BWb9qZRdBZwem1z/FeEeU31rPFTxFT/tZ0PyKNgBK9ifqal+hOvFphTA+zH atW6N75p4g6RNcasS5EQG6i/JGngkS/dQqTvF1ScKw+JSQq2KmADu54qXGF1eq9EwWR9 s/nlliZRAoDNhEQDNJ4jS7Gz47iPkJnh2IkKr1yoWBAJwTTNJJoEoh9dVYIOtnJBiAbP NKxg== X-Gm-Message-State: APjAAAUubc6swDeTaH1nXxm48AhyNQ/KPOikPfP9Vg8Kv0ZRQ/ZigKZP SRGK/F9EcS3YfsKNuk9/XIL7Gwnh+Jj0Z+YYWmmL43+z X-Google-Smtp-Source: APXvYqxk+202YhBpjDH3ZRPZupNDlt724zVe209eSt6yZqLm0ZdwIw/7MIuBKlMqXv4qrtHJKNvX54OGnnnx+l42beA= X-Received: by 2002:a92:1f16:: with SMTP id i22mr60866575ile.206.1582552533006; Mon, 24 Feb 2020 05:55:33 -0800 (PST) MIME-Version: 1.0 References: <8545d15e-ddd5-42be-8405-09697a077234@www.fastmail.com> <4d9688fe-cc57-44af-903e-05f4cbb1bbcc@www.fastmail.com> In-Reply-To: <4d9688fe-cc57-44af-903e-05f4cbb1bbcc@www.fastmail.com> Date: Mon, 24 Feb 2020 13:55:21 +0000 Message-ID: To: php internals Content-Type: multipart/alternative; boundary="000000000000917c8c059f52b95c" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties From: rowan.collins@gmail.com (Rowan Tommins) --000000000000917c8c059f52b95c Content-Type: text/plain; charset="UTF-8" On Fri, 21 Feb 2020 at 23:18, Larry Garfield wrote: > The with*() method style requires cloning the object. What happens to the > locked status of a set property if the object is cloned? Are they then > settable again, or do they come pre-locked? > > Neither of those seem good, now that I think about it. If they come > pre-locked, then you really can't clone, change one property, and return > the new one (as is the standard practice now in that case). If they don't > come pre-locked, then the newly created object can have everything on it > changed, once, which creates a loophole. I'm not sure what the right > answer is here. > As with typed properties, I wonder if there's a way we can introduce a new initialisation sequence for objects, so that there's a specific point where the object is considered "fully constructed" after new or clone. A couple of brainstormed ideas, with plenty of downsides I'm sure: An explicit finalise() function or keyword public function withFoo($foo) { $inst = clone $this; // all readonly properties are initially "unlocked" $inst->foo = $foo; // now lock them, perhaps also checking that no typed properties are left uninitialised finalise($inst); // or finalise $inst; return $inst; } A special code block: public function withFoo($foo) { $inst = clone $this { // all properties are "unlocked" within this special block $inst->foo = $foo; }; // from here onwards, readonly properties can't be written to return $inst; } Perhaps could also be used with constructors: public function createFromOtherThing(OtherThing $other) { $inst = new static('some parameter') { // readonly properties can be written in the constructor, or within this block $inst->foo = $other->getFoo(); }; // object is "finalised" when the block ends return $inst; } Regards, -- Rowan Tommins [IMSoP] --000000000000917c8c059f52b95c--