Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120290 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87765 invoked from network); 15 May 2023 17:50:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 May 2023 17:50:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 49AD6180546 for ; Mon, 15 May 2023 10:50:22 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 15 May 2023 10:50:22 -0700 (PDT) Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-3f3284dff6cso21924845e9.0 for ; Mon, 15 May 2023 10:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684173021; x=1686765021; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ERO3mSImPzQqQYyjZGpvNj2gYHBv9xz87dQGl4JfmTI=; b=Og76+9rM95YNtyi6BHv2oxoBEI8aApDHdMvNnujDqGpETFhOkW6tm1dwxqkd8HfuSI 9U4CSOjf4aOV4WX1lT78mPufhlQHIISAC3yktMYHxPFaP9b1pIvtMoeHTClD7kR+OFOT 1OlwsiaKCokVwsQCxfPhPehPCCJ9Vjlh9w9ct6gEPy9Ab6Rr4DRz2LJCxMhW386PmTDF 1lFu57WaszUSFiX9h/YbsSDDiSG6Siia+iVwWlnIyghh/GvWmkcS7RasSoe+pjQlSiHB 37cWFG6/Ftte1HynxdhBWK4fH4EyAqCRKwcCtCJ0BgAxQw1S6T02KGnaEF8f2TgitCrn MaeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684173021; x=1686765021; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ERO3mSImPzQqQYyjZGpvNj2gYHBv9xz87dQGl4JfmTI=; b=DJ9N4VKt10/7LUyPrPBL/CqXsLGeaA+rmZ0QXIe3AKlkotYA+SZEniULTWTvJ5L5AA HIdwpoBTzu5GoQS1bLvweY6V1pDw8ODGxDQvfY+9Xkt4AwKW5gO9edsUA+ZJCWSycnEl 2d4bNZ7V+eT6K4nYVVYRmga7aLkiHoiYChJohmG8iPffmeyz56mk/bRbE28//F6sjNCN kwZVQiZ3y0R/8/kF+Y/VYk1OHxTgBdh+zrGWyGVXWYGLJ0w67Nm22M/UgcBbLhQ3YJaf 6HcuaW+WPWjWZgHVb7Jn7bwFXhrT6t2MGVGRHu/v18HQrvqqIi7xPjOl6ly4fuDy3aSe U1Yw== X-Gm-Message-State: AC+VfDzz3yBA+cv33I7knfeTHe630vG5N2NKxELjNAVNS+LJETxxcVVL dSHalzClXQ0Qdqx1HZ2veusxNN3pi2Kigl/y+2z8Dlg2mKeBMA== X-Google-Smtp-Source: ACHHUZ7OBqI5kEZ/kTiEQ+rPMQ+jvBhcy991uylSHjiqCeW+xjPJw4RD5izjGP0+B7F/GWgdIhb7q3caoeoEpEYl6kQ= X-Received: by 2002:a05:600c:82c7:b0:3f4:24fa:ca1c with SMTP id eo7-20020a05600c82c700b003f424faca1cmr6540614wmb.0.1684173020606; Mon, 15 May 2023 10:50:20 -0700 (PDT) MIME-Version: 1.0 References: <641b1ca0-d33f-4f38-ae64-81b4abce24da@app.fastmail.com> In-Reply-To: Date: Tue, 16 May 2023 00:50:09 +0700 Message-ID: To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Property hooks, nee accessors From: the.liquid.metal@gmail.com (Hendra Gunawan) > If there is no forward compatibility consideration, can we simplify > interface definition to this one? > ``` > interface IFace > { > public string $readable; > public string $writeable; > public string $both; > } > ``` After carefully reading the proposal again, I think I know the answer for my own question. Short answer: no, we still need ```{ get; }``` to enforce the implemented class. There are two different things here: 1. enforcing the implemented class 2. enforcing the caller site If there are only ordinary properties, then ```{ get; }``` is truly useless at the moment. On the other hand, virtual properties need rules to be enforced, since there is no default hook given to it. Since PHP lacks method definition enforcement at the caller site, I assume that property would suffer the same. Since we don't know what type of property is in the caller site, static analysis tools can benefit from ```{ get; }``` to produce a warning that we should not assign value to the property. A more complex check should be performed to the implemented class because the property type can be determined directly (if i am not wrong). ``` interface IFace { public string $readable1 { get; } public string $readable2 { get; } } class CX implements IFace { private string $_propx; public string $readable1; public string $readable2 { get => $this->_propx; set => $this->_propx = $value; } public function consumeIt(IFace $par) { // these statements should trigger warning by SA tools $par->readable1 = "hello"; $par->readable2 = "world"; // OK $this->readable1 = "hello"; // this statement should trigger error by SA tools $this->readable2 = "hello"; } } ```