Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123791 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 5331E1A009C for ; Mon, 24 Jun 2024 21:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719263926; bh=0XlRN+q5EYA4A48IdXiUkp9Ks7bsAbY4uErreadp9p0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=PgDEnScuf9fsNDo2SKvwr7d6MFOi6AitVessbgfcPxYmiX+PHmCK2+1Qf+qBPVb2h PDVfw3CbcFUYYDSzMETlgH2is+A7py2GSOSCXYaJSwwoV1mNVnFDZjjaSfG4gRCbPF SaFgLRb98NaUenJt55vRtYMWnr+Nm1lgALAQKT0qJZrP8ZGJeadX47AkLD5/+W3Tx4 9vR1bmbpe+xuJApLFDOxx/faJk2/6ce6xu5LIj78+7fKJJn3fVVobYHzHVN+RP0X5o Jtq4lIfm7kjZLoa8f36B1n0jqgGVZNL2FzHplHtJu887c/yIN2hzBeyZsVRUshoSzh GSD69pSHPyDbA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 243AA1804C6 for ; Mon, 24 Jun 2024 21:18:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,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=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 24 Jun 2024 21:18:41 +0000 (UTC) Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-52cd87277d8so3127583e87.2 for ; Mon, 24 Jun 2024 14:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719263844; x=1719868644; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=0XlRN+q5EYA4A48IdXiUkp9Ks7bsAbY4uErreadp9p0=; b=ILiK8/gIBQ2ek+BJevztjh5Mi2+bsHSG9h1n8VmpYEgAykmAolKv8v0wV9mOdODPGD hzvGIHmr0/HPGwRU+YBNtvDIuVb1+HSG5ZcQT0U5dyCS6JipxAy9V1csF1tTp9FpveJH QbrvH24URqPbUslZKCo8MyHt6g+7LoYcq5YLacKVSB4Kb80htp1WKe4qWPLOTP+1+poI a15I9G1S5+corw7CMe3/PJKiZf2TgCiZ6lN7dI0A4bXuFyvQINpkuJ1GhExKJU2HkJDr KLLkhCyRQ6n7FTNwN+7ztMwO8+g8rXMyX7lxJWqsgq44pi/aBxzXHlEVtMLg8EJqAgRf vJFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719263844; x=1719868644; h=content-transfer-encoding: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=0XlRN+q5EYA4A48IdXiUkp9Ks7bsAbY4uErreadp9p0=; b=D7R3tZ4r5e0Upu53Twg99b52bs9ae9TmBOuhBKMuk6tKbeNuE4dahwwL4wlvcpwGVV lhpS93YFiAww9AEcMvwlRmeudGS9RChUSWS/5Dng3u1wU07NLI5AvJ9EnIfPDsGjhJvM w0U3RwxPlbmrkUbHkI+pj45bKxmfGlQ5hcWKOWpHdFsp9UhYXVXCutZ+W8pdg4476XBu lxX/0lmxUMbKZTBTZxS6y3qPuEPe+1vzl2jUEIPxcBRA4gpVFhIhjiRLibom05zk9l36 L+UK5muuidNLEMnFvzbMoAF9O67+Zn40qIArfKs7b4/lhx6h5F2NricG+UcgANSe0h3z RWeg== X-Forwarded-Encrypted: i=1; AJvYcCXWYV/6HCNVKdBXdMfzR0EV+PMPoBtLPR41wjgJmG9zaiFeARVrdY8/kncunecBMrnhMlj1jdtvJhjSs+VeOO5SE5Zr/EhR0Q== X-Gm-Message-State: AOJu0Yw52XFCo2bE3JcYjt35+DQAHxRuL/JtFiVd13khoRuD9J65thUW EUQYpAFI9zGAgYfP0mwCYS46RxJkX5thJFwDsA1xfLxax8LPsLq84r+5zTAEzPhCaL0LzVpEFIa 4o+hUCQjaI7g+yaBSf6r1oo6Cl48= X-Google-Smtp-Source: AGHT+IENxTYpH1xGAiJTxQuYEVI2x+rAPeYLpx6gC1EtwEbGxrts1O1O03Uvw+wlgdAQc8Yffh8il8wLhRJCnepxGxA= X-Received: by 2002:ac2:47e8:0:b0:52c:d905:9645 with SMTP id 2adb3069b0e04-52ce183293cmr3562720e87.13.1719263843596; Mon, 24 Jun 2024 14:17:23 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <88D83E92-94BE-4548-B398-8F5C74765FFD@gmail.com> <501a6892-377b-4156-a18e-a9b3eb33d629@scriptfusion.com> In-Reply-To: <501a6892-377b-4156-a18e-a9b3eb33d629@scriptfusion.com> Date: Mon, 24 Jun 2024 23:17:10 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Static class To: Bilge Cc: Claude Pache , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Mon, Jun 24, 2024 at 10:22=E2=80=AFPM Bilge wro= te: > > On 24/06/2024 09:27, Claude Pache wrote: > > Hi, > > Hi Claude! I really appreciate your feedback. Everything you highlighted = is an important point that will be included in the RFC! > > A general remark: I appreciate that a static class does not impose arbitr= ary restrictions (like: implicitly `final`) on the class beyond what is mea= ningful for staticness. On the other side, I don=E2=80=99t think that we sh= ould support markers that are technically possible, but semantically meanin= gless, like the `readonly` marker on class. > > Great point, `readonly` and `static` should be mutually exclusive and gen= erate a compile-time error, since `readonly static` properties are not supp= orted. > > Some more specific remarks: > > * In the intro: =E2=80=9CA static class is a class whose members (propert= ies and methods) are all static=E2=80=9D. One of the most important point i= s missing, namely: It is meaningless for a static class to have instances. > > I thought that was covered off, but I'll see if I can word it better. > > * In the =E2=80=9CProposal=E2=80=9D section, it should be stated explicit= ly that any attempt to construct an instance, not only with `new`, but also= with any of the `ReflectionClass::newInstance*()` methods, or with `unseri= alize()`, or with whatever other mean, shall fail. > > Great point, I'll include that detail. I think we're also missing a simil= ar detail with respect to dynamic properties, which should of course also b= e forbidden. > > Should a static class be marked `readonly` or `abstract`? I think not, be= cause those have no real semantic meaning for static class; their effects o= n static members are only consequences of their intended meaning on non-sta= tic class: > > * Unless/until the `readonly` marker may be applied to static properties,= the only effect of such a keyword, is that it would prevent the creation o= f static properties. I don=E2=80=99t know if that restriction is useful, bu= t in case it would be used for that purpose, it would be hijacking the `rea= donly` marker for a something it wasn=E2=80=99t intended for. > > Agree, as above, we'll make them mutually exclusive. > > * The main purpose of the `abstract` keyword is to prevent a class to be = instantiated, which (in case of static class) is more semantically describe= d by the `static` marker. Beyond that, it just allows to declare a method t= hat, if implemented by a subclass, should have a compatible signature. Most= notably, it does not prevent the other static members of the class to be u= sed directly. > > I tend to find inheritance is not a very useful concept in static context= s, but others have already pointed out that some have found uses for it. Du= e to my lack of experience I cannot confidently say that `abstract static` = has no value, but you make a compelling argument. Happy to add a similar mu= tual exclusivity prohibition for this keyword too, unless and until someone= protests it with an equally compelling argument to the contrary. > > The RFC says that a static class may extend a class not explicitly marked= as static, but with no instance member. This is not sound, because a class= with no instance members is not necessarily static. The most obvious examp= le is `stdClass` (which has no member at all, even if their instances may h= ave properties). > > Do you mean it is not simply sufficient for a class to be regarded as imp= licitly static by virtue of the fact that it has no instance members? I'm n= ot sure I agree, but I may be missing something. If we extend `stdClass` th= en we gain nothing, and our class so extending it can still be safely marke= d static, can it not? Please elaborate so I might understand better. > > Kind regards, > Bilge Hey Bilge, > Do you mean it is not simply sufficient for a class to be regarded as imp= licitly static by virtue of the fact that it has no instance members? I'm n= ot sure I agree, but I may be missing something. If we extend `stdClass` th= en we gain nothing, and our class so extending it can still be safely marke= d static, can it not? Please elaborate so I might understand better. I think it is sound in theory, but in practice, it will be a foot gun. Imagine if you were to take my HTTP code library and make something static from it. Later, I added an instance member. Now, when you upgrade, everything starts crashing because of one little change unrelated to your code.