Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109319 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68997 invoked from network); 26 Mar 2020 04:12:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Mar 2020 04:12:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 38D5A1804E6 for ; Wed, 25 Mar 2020 19:37:11 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, 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-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 ; Wed, 25 Mar 2020 19:37:10 -0700 (PDT) Received: by mail-lj1-f177.google.com with SMTP id q19so4774036ljp.9 for ; Wed, 25 Mar 2020 19:37:10 -0700 (PDT) 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=DQWcuMQzU0W3bFad7LjAn9ng7+dIUeBBhTG4O9+Rpnk=; b=YUwE3Id82e+BumaYdBHTn2xclDmOoWZsvSUIG4CV28XqdSbgzyVDVTHZn37w262Biy avRt92yR2VnkD0FGvyeHanVTyI1N0/ZAoRCPF500B8wOG9Vg7hSdCwq5E+qP92eEiR0e bXEgi4DJJB+aOx3CeqQyzTZHH+UjoUKx+hBj+Kzkrq/RyjbIseyEkFz/qxJd8zsJ8wcK tPWXomHogACV3D29rFH5vjbM036GBRj82TqYZXgRA3vqAemNkVzw48S8U2cdnO4S3fOZ KR3gPhHjyDCl8D/qWJV4MUb4R//SmwrbvxlX7tl+osE5Mr+oP2mgdKuOLkOU9DPfd9O5 5boQ== X-Gm-Message-State: ANhLgQ2d4d0+WhpaX15KD5nXshYmVo2Tp1WDXtVFHk8PA1YwIbGUM+Tl 6pQ+9+xMHy3fOc/l8aQuP6+5KetI9J2CKhhIcubf+qFr X-Google-Smtp-Source: APiQypI4B7C7UrCZKWf11Enx3x4bOcY+A6dYNLha/qoWug+DQ84oFZbz30eVx5lwqi4p0CK1JdxhR3THOpftwDbqy+M= X-Received: by 2002:a2e:8513:: with SMTP id j19mr3872572lji.27.1585190226057; Wed, 25 Mar 2020 19:37:06 -0700 (PDT) MIME-Version: 1.0 References: <1b781e1e-3f27-485b-ab47-5eeaf9496548@www.fastmail.com> <56f4f7bf-6086-4e10-addb-aba93ba23c5e@www.fastmail.com> In-Reply-To: <56f4f7bf-6086-4e10-addb-aba93ba23c5e@www.fastmail.com> Date: Wed, 25 Mar 2020 21:36:54 -0500 Message-ID: To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Improving PHP's Object Egonomics: A broad analysis From: jakob@givoni.dk (Jakob Givoni) Hi Larry and Nicolas, On Wed, Mar 25, 2020 at 9:24 AM Larry Garfield wrote: > > I'd like to propose something on the topic. > > I'm adding object literals to the mix because that's another feature of the > > language that we're missing a lot IMHO. > > Actually, there is one existing syntax for objects: (object) [...] > > [...] > > 2) What's its order of execution with the constructor? Vis, does the constructor run after __create or before? Does __construct get any parameters passed to it? That's the interesting question, though there's probably not any sensible answer that works for all use cases. However, if this kind of object casting (object literal notation) was limited to a certain (extendable) internal class (SPL Struct?), we could have just a final public function __construct(array $properties = []) that then delegates the validation to an abstract __validation() method. Would that at least be a useful alternative to constructor promotion? > In that syntax, you have to remember which one comes first. There's no indication for the casual reader why > > public private $property; > > and > > private public $property; I'm wondering - are there any use cases where you would have private read and public write? If not, maybe this issue can be simplified by adding (f.ex.) "semiprivate" and "semiprotected" attribute keywords, the idea being that they give readonly access to the anything else. Though I think it would be great to have a nice, gracefully extensible attribute syntax, maybe it's not necessary to fight over that for this particular issue? > Either way, what matters is who is in charge of dealing with the issues > this might create. In both ways, what matters is that the original author > won't be bothered for things that are not its responsibility. "I broke your > app because you messed up with that private property on a class I > authored?" no my problem. About final, I usually prefer using the "@final" > annotation: it expressed exactly what I need to express as the author of > the code: "if you extend, you're on your own - but I'm not dictating what > you can/can't do either". > > I think this reasoning applies to my view on immutability :) :-) I can relate to that in general. Though for immutability, I'm not so sure anymore...