Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113531 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10571 invoked from network); 15 Mar 2021 06:45:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2021 06:45:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7CF6A1804D1 for ; Sun, 14 Mar 2021 23:39:23 -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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 23:39:22 -0700 (PDT) Received: by mail-ej1-f45.google.com with SMTP id p7so52928610eju.6 for ; Sun, 14 Mar 2021 23:39:22 -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=aOHAYXVBBZiTIRoBHZJVA5Um2DrKlPiVdesYuT34nY0=; b=Luwl5pcwyDFuS8Y2nTGrXbaGBvQ+JMpa0mMG2x+V3q7aAnUuvia6SwqTmqHFDzesR2 ycaFSW+41IwInqJuK4tQLdcEp/qIn0SI2DLPfNckkL8qKCi4p/g8gtXsgRo7qYGtS3kH BL9sFjM2Lgo3VMAnN7lxWxM5LrtiOZpg8l8X+q4r3amFdj39sk9Xwbz3y0VhRbhdsoQY 4WhaAzaedMbxPgxCPKpKG0i9MHfPEMxnz7Mi5rBQBPJAgJw+I6ei8ltpYFKyCLUXKpC/ +UHIuf7L2EC5/RbzV5dP4jBnlNbeIDcKRBYWQ/DnVwogMh6Qt5gWw66nzityJxRW/l89 49Ww== 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=aOHAYXVBBZiTIRoBHZJVA5Um2DrKlPiVdesYuT34nY0=; b=NJlio+m3+pVWSNSuSUdfFT9bK2+Rkk38kP4xkuhtzfvpbSKnbnbU3cGKqBHdI2Srt/ l4Y0plOu13IV4HrWIuMnH2lA/AOvuNvRBLdpdQvITOTgf+H7ExvhtQBLAU+3eyNv/lrT sPNZO/YkCsDr8KIonRI2VmuX1h9e/k3Lv+TMSfKY+env/D2Ebw7d9fveD3UJcq4fu0wa +c0W9fxnKDH4ztDeJOwpEPyueAo9mtqUnoyEXgftE5am9NpOT1FQT1fF3kapzgDfVdk/ 7B0KR3mBKaJb2iqg9khUQu/F7KFqxi2aAnNeqT74XC694xltt3Ol2feaf6IRx13pUw/g duvg== X-Gm-Message-State: AOAM533V1zhO8xsEzKIYvPSzUhDLcvGgcaPHJWMC1TsQWUmZ8zNUf8b2 Dd40I5YXYWsNgHz89Gf8IvDeXnDsLhclBEYW0mY= X-Google-Smtp-Source: ABdhPJy6rKp4GB/96zxuBAx4hnrJ+XWulNAyrKMpQM72p536mpkYVm2FRSflnnxRQ3bIwqoArLNNFCykE8p4qG5FNpI= X-Received: by 2002:a17:906:3849:: with SMTP id w9mr22111075ejc.7.1615790361769; Sun, 14 Mar 2021 23:39:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 15 Mar 2021 08:39:05 +0200 Message-ID: To: Gert de Pagter Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000008b7a8a05bd8d82b2" Subject: Re: [PHP-DEV] [RFC Proposal] Allow methods to 'become' static From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --0000000000008b7a8a05bd8d82b2 Content-Type: text/plain; charset="UTF-8" On Sun, Mar 14, 2021 at 6:02 PM 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. > I've encountered this issue working with legacy codebase. I recommend having two versions of the class, the old with static methods and the new with non-static methods. Logic would stay only in one of them, having the other as a wrapper. Migrating from static to non-static would change the injection as well as the calling style. > > 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) > The issue exists also for class extended, not only for interface implemented. Even if in general, static and non-static method have different rules for inheritance and they must stay in general separated, this idea is not completely bad in PHP where the concept of late static binding that happens when one calls $object->staticMethod(); could allow such a thing to have a sense of existence for upgrading from non-static methods to a static method in the inheritance chain. As my experience with C is not vast, I'm not sure how the inheritance chain for static and non-static methods is represented internally to allow such change. Also the calling place logic would maybe need changes to seamlessly use polymorphism logic or late static binding depending on how the method is defined in the class of the object called, if that isn't already done in some way. As I want to learn more here, I will try looking it up to understand it. But overall, it sounds like it can be avoided by choosing a separate chain of inheritance approach. Composition over inheritance. Regards, Alex --0000000000008b7a8a05bd8d82b2--