Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123803 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 1AAE61A009C for ; Tue, 25 Jun 2024 04:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719291368; bh=n00mLOuLhvZmrSCaFvcKZ3PYFVUNRy5rI+Dku+vtPgw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=nvT1ZpdVlQiK7oyx6F3yn4jsIVnDrerGXck5DpsBfpi7XOW1FmrO1Maq7EwQF1IRK lBF0P7TIjUd9g6YSO9TtnKWETCIa04qFO4JQ5+DoJfyWKX0qAqI7skcjmOczRV2bpF ZdlF6foNqh8wfMbYyQpIukqp3QvJcWvUoTB2m2AN+zutQuWMn5NkmIfAMIqyezdvza 6/i4kFXeeMc01e9Njxpqau2l++ksWz95xgviSR8YCMBvW1TtkOrsn9Sxc5vQvSURCR Me26K4Au2UP7XG+yXil4kVCpB3cLD/wkTWpUEgyopILFEsJ9fq42zZIfpkEbmq6Cbn 1tMNQxaBOE/TQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9D86F18005B for ; Tue, 25 Jun 2024 04:56:07 +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, HTML_MESSAGE,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-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (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 ; Tue, 25 Jun 2024 04:56:07 +0000 (UTC) Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-dfdff9771f8so4700973276.1 for ; Mon, 24 Jun 2024 21:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719291289; x=1719896089; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=n00mLOuLhvZmrSCaFvcKZ3PYFVUNRy5rI+Dku+vtPgw=; b=APIVy4J2V2STcJVFYoFt8rnC5Dmjq98e9cic0LYNK9aP8Pe2N+EsO28kiZ3zfMQSN5 csrhN1Ys+R4EoHKVZgxzYsLzVJ33fWoe8LKs+kLCsx8DBkU7ZmdVfhjwWfzsyNuRwds+ XNdtGTwxnxNc1vFSocRlMCNm/XxdbUt9byBqKuKLx3/s0hQRPb5gXVBglKujUVcIVEb+ fLzThV/vvcziW6lfBFlYllzfVvej+chaK9dq4EboOP52Hm9OGfdDgu/6L+wY69Kj6tVf jmjIVdquQ/Ug5umbHrDX/AQ2iocpVGY+yq/rRNWhYuWI8D0HprAi477N4Nz9dVC7enTg x1Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719291289; x=1719896089; 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=n00mLOuLhvZmrSCaFvcKZ3PYFVUNRy5rI+Dku+vtPgw=; b=VLWN463w4T0L/bNfeoPhfMJoBb6obLSevIEiUhQaAbLmqh1OLFzoUC/6JzufzvcjzP jUxK+3e9q1pskPWOVTRtnpl2BjzmYcwnu0vu0WNPiKGaGZ8zULL9XdIQzKpUMrUGhFBt mQZvfHRVmQuCyeW4hwjLCkvDj11GdwEQtMRq2CskCN6U4P67HO37NgRtumcpLMVpqRqb peXbEUHWMBOVO//jUE2n5ye+CkUL0q+pS/fKx4k78sRgv5ay9eaFOAptwP2ZgUFYsva9 +fI+UpfEnyQOwk5ko5b86CxijSvUYqhPdDDB1dlNkoMsnxjmCFze3qKZ5zLIM6QKPxfQ KRSA== X-Forwarded-Encrypted: i=1; AJvYcCVbNAT7VosWJiHbRJV+Wh9UGm0kS/N5NZlsXSuIla5zlg9D8lT4P2mnO0cefg74/MQn9QRb+snziLIUzReTkZZr4Q1igDEokw== X-Gm-Message-State: AOJu0Yz3rd/0zbqxHqA5+K4jOQOaL8tTyWjAhob3SukgeDvWVEHHDqcP 7yR4bpC6FLuISP301XC2UZBJ06kL0Pw/t7RnrVez4kPoe1m1a1cy43BomcOe4TPI9bVPt5OYisZ kHwRvLXec5RPfah1bcC9uv8AnlOw= X-Google-Smtp-Source: AGHT+IF2CbXDOj79xzWvXlFLEZSY/Hs0dWG4KSHu+8LDZFt4QEguqSUbPdkSlEvC3+7um5IcRqpbq4Bg5ZwTs1/FAvM= X-Received: by 2002:a25:aa31:0:b0:e02:b622:ebea with SMTP id 3f1490d57ef6-e0303f2ae8cmr6229317276.4.1719291289596; Mon, 24 Jun 2024 21:54:49 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 25 Jun 2024 07:54:31 +0300 Message-ID: Subject: Re: [PHP-DEV] [RFC] Static class To: autaut03@gmail.com Cc: Bilge , php internals Content-Type: multipart/alternative; boundary="00000000000094fa5d061bafb2e1" From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --00000000000094fa5d061bafb2e1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 25, 2024 at 1:00=E2=80=AFAM Alex Wells wro= te: > > a static class member can never implement an interface's contract > Well, PHP is a weird one here compared to other languages Interfaces can contain contracts for static methods and they are checked just like usual non-static methods. Example: https://3v4l.org/8cuXW With late static binding, you can define static abstract methods and basically do code reuse through inheritance. Example: https://3v4l.org/pid7W I'm not saying I would ever use such a thing, just that they exist and others might find them useful so why build limits around it? A limit is just extra code to maintain and make sure you use it consistently. I believe that a static class should have the principle of no allowed instance and only static methods, without any impact on inheritance: - There can be a static interface and a static abstract class - A static class can extend a non-static class, or implement an interface or abstract class as long as it does not require to implement a non-static method. - A static class can be extended only by another static class - As static interface can be extended only by a static class Basically, when a static class gets into the inheritance chain, all the extending classes will be static and there is a guarantee that there will never be an instance of that class. Making sure a static class does just that, limiting the methods and properties in it to only be static, will keep things simpler going forward when thinking about interactions with other features. Like readonly static class would not work right now, but it will work if readonly will be implemented for static properties, and that should be doable effortless. Alex --00000000000094fa5d061bafb2e1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Tue, Jun 25, 2024 at 1:00=E2=80=AFAM A= lex Wells <autaut03@gmail.com&= gt; wrote:

a static class member can never implement an i= nterface's contract

Well, P= HP is a weird one here compared to other languages

Interfaces can contain contracts for static methods and they are checked j= ust like usual non-static methods.

With= late static binding, you can define static abstract methods and basically = do code reuse through=C2=A0inheritance.

I'm not saying I would ever use such a thing, just that they exist and= others might find them useful=C2=A0so why build limits around it?A limit is just extra code to maintain and make sure you use=C2=A0it cons= istently.

I believe that a static class should hav= e the principle of no allowed instance and only static methods, without any= impact on inheritance:
- There can be a static interface and a s= tatic abstract class
- A static class can extend a non-static cla= ss, or implement an interface or abstract class as long as it does not requ= ire to implement a non-static method.
- A static class can be ext= ended only by another static class
- As static interface can be e= xtended only by a static class

Basically, when a s= tatic class gets into the inheritance chain, all the extending classes will= be static and there is a guarantee that there will never be an instance of= that class.

Making sure a static class does just = that, limiting the methods and properties in it to only be static, will kee= p things simpler going forward when thinking about=C2=A0interactions with o= ther features.
Like readonly static class would not work right no= w, but it will work if readonly will be implemented for static properties, = and that should be doable effortless.

Alex


--00000000000094fa5d061bafb2e1--