Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115707 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8006 invoked from network); 13 Aug 2021 14:25:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Aug 2021 14:25:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 333C11804BD for ; Fri, 13 Aug 2021 07:57:13 -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=-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-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 ; Fri, 13 Aug 2021 07:57:12 -0700 (PDT) Received: by mail-lf1-f49.google.com with SMTP id t9so20363766lfc.6 for ; Fri, 13 Aug 2021 07:57:12 -0700 (PDT) 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=/Y5y1WS1QtDQ9FPVFGzFQbsCgdm5DK1CbhVWMPgpKpw=; b=IQ8tYLmm34R2ry8an7lRja706OGm0sCFMd6H4g17ipotn5fUL0TXWEXCiYBO48hp+R t374Va2/McmVRTiVFNELi7vc2/W6TiIew1/ETi2KhIkrInnBp+i5T3VmzgoUqipABXc1 cVf9a3D97LsALl+fzrjYMTZDKYU9Gv/Fiq7lay8pR/i2RjtzArc9gHjzdUSQpBMqB3Ct 5ZyMFcdDzBeVlRBh29kASIJrEgMOJSCVKyLhRQCHBI0DDElbT5S82uvXMJbYYh8HQKIQ B8GERPzQ1Kzbxt9ZyZzauh9ANDmEo9sq49Ud8bc9g0+KhWo+M5lC+z7MuJgxVUzCNFnj dPrw== 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=/Y5y1WS1QtDQ9FPVFGzFQbsCgdm5DK1CbhVWMPgpKpw=; b=QGJCLFB8cgYNc+TXjdoBKQ/B7ucUz8SXW+PXaefMC6U0FaHdnRjKgnAiP61UI+uzbM o3YTaNi9xV8clagMve2gB9Jmzl9oVDUZBVmqudDxTvteRxGQeAup96rdGVZZdJMTg4MY 2JdryBYp5GzT27STaMG+idA9GiBFoeWT6NrohkDRB+zKskQGzqBCjA6JnsikLl1JtHdl hniNiFJWsasWWMi8TqrnT0itcC2ZTEufDLAfWyuMFI8cC7VOm/QUVTGuJtxDnWTsvPVl raoYE8TvtGUJInNXSwQf5PYuGn3vkxqJ5X+xhdCbqGQaPoxLwPsNpMr0ci/O/sEuv/X9 jcbw== X-Gm-Message-State: AOAM531NOBw0MASx0JaB4s3sCUrK5aUqUJ/DLYtzYjXJNv7wl+ZTqujU Z++OY0GPVVfAPrHS+C+iyeI/tDQGxIgE2i6Um2A= X-Google-Smtp-Source: ABdhPJwVhh9JFpbO9osplczTZewxgkPr0S1ESyJ1ZJ2kfxvWLsz1ljF8in8suicDr8q4TX+Yqfrz6ZUd07teGeHTvNU= X-Received: by 2002:a05:6512:1501:: with SMTP id bq1mr2001304lfb.286.1628866630956; Fri, 13 Aug 2021 07:57:10 -0700 (PDT) MIME-Version: 1.0 References: <42b262eb-0d9b-8feb-cc3d-da3e36e14d1e@mabe.berlin> In-Reply-To: <42b262eb-0d9b-8feb-cc3d-da3e36e14d1e@mabe.berlin> Date: Fri, 13 Aug 2021 16:56:54 +0200 Message-ID: To: Marc Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000ecb91005c9721073" Subject: Re: [PHP-DEV] readonly properties From: nikita.ppv@gmail.com (Nikita Popov) --000000000000ecb91005c9721073 Content-Type: text/plain; charset="UTF-8" On Thu, Aug 12, 2021 at 9:16 PM Marc wrote: > Hi, > > As 8.1 adds readonly properties I wonder which build-in properties > should be defined readonly. > > Currently I could find build-in readonly properties only on PDO and DOM. > > > Very incomplete list where readonly properties could make sense: > > 1. Enum properties: > > enum Test:string { > case TEST = 'test'; > } > > $case = TEST::TEST; > $refl = (new ReflectionObject($case))->getProperty('value'); > var_dump($refl->isReadOnly()); // false > var_dump($refl->isPublic()); // true > $case->value = 'foo'; // Fatal error: Uncaught Error: Enum properties > are immutable > Yeah, these are a perfect use case for "readonly". Done in https://github.com/php/php-src/commit/caefc6a50789295b0993c4e657c825484650172a. This actually fixes a bug, because the homegrown "readonly" implementation for enums was not quite correct. > 2. DateInterval->days > > $interval = (new DateTime())->diff(new DateTime()); > var_dump($interval->days); // 0 > $refl = (new ReflectionObject($interval))->getProperty('days'); > var_dump($refl->isReadOnly()); // false > var_dump($refl->isPublic()); // true > $interval->days = 2; > var_dump($interval->days); // 0 > The DateInterval properties are currently implemented as getters/setters on some internal state. Some of those are getter-only, but probably not fully immutable. 3. Exception properties > > Exception properties are protected but does it really make sense to be > able to modify an exception property after initialization? > > I know this would be a BC break :( > There is definitely code out there relying on modifying both protected and private Exception properties, I don't think we want to touch these without cause. Regards, Nikita --000000000000ecb91005c9721073--