Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113520 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63806 invoked from network); 14 Mar 2021 19:47:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Mar 2021 19:47:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CE60E180087 for ; Sun, 14 Mar 2021 12:40:45 -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-Virus: No X-Envelope-From: Received: from mail-ua1-f49.google.com (mail-ua1-f49.google.com [209.85.222.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 ; Sun, 14 Mar 2021 12:40:45 -0700 (PDT) Received: by mail-ua1-f49.google.com with SMTP id 97so3554274uav.7 for ; Sun, 14 Mar 2021 12:40:45 -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=MOLR+d2G3UYJ991i1MbLa88YI2jdIihEmXQJQeh4BL4=; b=q3RlrjYjKK/cjXwBziXtPH0znpx//YnxQUb1jcPktWHEW4gUS+IJGmM1x+QIduzBLB fQQtMSVxGIM0dZXHmn4wW7x/yRc18Tr0i/oWnVpK8k5yUIOKFfzlvdISFgcoZmF6ZcZd u8BnqF5Yl9wiv14U+eL33so93ttSR2wWm7+Sy5hsQrn9oh8IY+gqnx2NSozA7EXx1aeR d9YQgwDnkPwB6b/bt0ohGyTKt+Q4Z7n6fJgbu4E+vTudPAtvAvlA2tNVDbQOQOJV2v7D xvC+mWKHbq86tOIqvjFyUaC6n1jd1nXo2ENCOQVFeT6oWcsgX+aXKVysdNG9qvAG0xrH siRA== 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=MOLR+d2G3UYJ991i1MbLa88YI2jdIihEmXQJQeh4BL4=; b=H8+2b8+6pALHdG7wab6bkPM036ZzDkN+1cqO/t/BzSgIHetgd4Jyuc8X4N62ciDFa9 0a/Tn/eMRSgRDOaE+27/rxXjon1qUOGothVPawGvZo7MxXML1qDXSRggB3WykyvuQAZX 4dNZM95Jzxqlg+aVtbpScl4Qi62FxQON1mOeMe+x7TiNLtpSoUPO9sZo7phQVI1YlsPH SD6HKjhnJpDXT6J5rlDXMlWVD/xea4UKssw46Ofk7D6W8I0kI7770ZYqsSRwAE4YxJSa n0eHolQR/1oQBrwFQSm62n5ebvbAK/GKYXlLJjiYhd4BG/zdjJ7xvIIKFxaAECdSRkvV eyjQ== X-Gm-Message-State: AOAM5319GyvaH5DpvZqs6QnhuZVU1WRZ59PUnEU6aqLAVdbXceYKfEbq z+qJ4rhpfOu5RJ/Xv01/dPWjTkwxsvZxV74qJx8= X-Google-Smtp-Source: ABdhPJwDOGM9a2IYnptGrYyn5Z5PFEMjdd5lC8Eiy6Z8iGO2zFufXlXm36NtzcA4a+0HxORORjmquUrbbOCVrygVBk0= X-Received: by 2002:a9f:24c7:: with SMTP id 65mr3146367uar.119.1615750842786; Sun, 14 Mar 2021 12:40:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 14 Mar 2021 15:40:31 -0400 Message-ID: To: Gert de Pagter Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000007a89105bd844f79" Subject: Re: [PHP-DEV] [RFC Proposal] Allow methods to 'become' static From: matthewmatthew@gmail.com (Matthew Brown) --00000000000007a89105bd844f79 Content-Type: text/plain; charset="UTF-8" On Sun, 14 Mar 2021 at 12:02, Gert de Pagter wrote: > Hey Internals, > > Recently i've been working on an older code base, where we have a lot > of classes with all > static methods. We've been moving to injecting the classes, and > calling the methods as if they > were not static. > > I wanted to add interfaces to these classes, with non static methods, > so we can pretend in our implementation they are not static, and allow > us to easier switch to non static methods in the future. > > This is (currently) not allowed by the language: https://3v4l.org/WKdvM > Is there any chance of this being possible in future versions of PHP? > This would only allow 'normal' methods to become static. Making static > methods non static would break Liskov substitution principle in PHP as > you may not be able to call the method in the same way. This means you > can't have a 'normal' method become static in an inherited class, and > then become 'normal' again in another inherited class. This works the > same way with co/contra-variance in return/parameter types: > (https://3v4l.org/j1SO9) > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > It's maybe possible in the special case of implementing interfaces, but it's unsound for general inheritance: someInt; } } class B extends A { public static function getSomeInt() : int { return parent::getSomeInt(); } } https://3v4l.org/WnaES --00000000000007a89105bd844f79--