Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114165 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56833 invoked from network); 25 Apr 2021 21:05:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Apr 2021 21:05:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 87CC71804E2 for ; Sun, 25 Apr 2021 14:09:15 -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-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) (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, 25 Apr 2021 14:09:15 -0700 (PDT) Received: by mail-ua1-f50.google.com with SMTP id i5so331878uap.5 for ; Sun, 25 Apr 2021 14:09:15 -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=L/dixS8PkWpyRDNNKTACLLD7D1cFOGC3rZw1kZXXhIo=; b=QlGEweYtTkkCg6cGHouEc34GcPfxjilYBLx3h/CitHyhl9pTw5jQwpvEWvTHTiiupB s/7DRqbVvy//UZiiqhMTiKPt5U8t3oYI1eWMTzei/4pZF78j160U8ffl5Z0m7u3+6KW0 Mwls7VYp94fAD0Nj/T/trTfqWSvn0O3HUCXlChe45dE/6pd5DoLS+eoGZrDuTp1LwsJZ jc7SbjMgEw06N82+glXKJQbKRlztImuli7gGMx/rpnd0IceSFObOg0aeLuQ2DHg/9VHs cPzQFn4w6NGES6dd4EpRTtPs9byKOoqkUVpz/ldg8Xpl1HexYr9qkSD17yQX/qpCPBSf k0bw== 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=L/dixS8PkWpyRDNNKTACLLD7D1cFOGC3rZw1kZXXhIo=; b=ZbJznwlvnXAhTFMnuvuqNPFIHtmjx1fXQ10QefPVGg64mBuGU5FvZbliBHhwXejvdf wIy5v0QI+yCSGLUuzU3YLi6t264Oic4oe6gjj7qBZgF8p5XV7cjYUqhbOJ492uiX8fuT 7xqQ4Mkkve0oTQpOVRBBHOrzoVc1VJa2Y0udKN7Y/7T7xScZcKZeb/2g3jLjT7IRtJ5P Coaaozq3z1FtO95FdEZG7qk3QLLNqlotkr2D+KqrzCBGubk7J0C8CSzWsjZ3zU3PtLB/ 0vJ9Q0dKYNvhuqleIec1uTeIqMKWCAu7Ct37WD0N7WFRGDj0OaHyBCfkNxKjrHQroWft Maow== X-Gm-Message-State: AOAM532XJRxKNNNY+aGbDhw8JY9JN/9VpMG1T3thm4vosHoGHuQvPVBU p7GBfeyy+x/B0qt8LVZ76dMsXzzIMy+AC0q/g3w= X-Google-Smtp-Source: ABdhPJwtrrKCuQ4QlAq5ubro0vnsTvJo6ym7O6aoOxTRfO7rofE62nCloDrmlvaV0L3MIThZUosFF6lCUN74VPaR/r0= X-Received: by 2002:a9f:2422:: with SMTP id 31mr10098641uaq.68.1619384951414; Sun, 25 Apr 2021 14:09:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 25 Apr 2021 17:09:00 -0400 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000c8a46a05c0d2705a" Subject: Re: [PHP-DEV] Method overload support From: matthewmatthew@gmail.com (Matthew Brown) --000000000000c8a46a05c0d2705a Content-Type: text/plain; charset="UTF-8" On Sun, 25 Apr 2021 at 16:12, David Rodrigues wrote: > I know that this discussion comes back from time to time, but now that PHP > is quite strong in relation to argument typing, I think it is worthwhile to > have a quick discussion about it. Maybe to PHP 9. > > One of the things I remember that was a big problem was the performance > impact in determining what the ideal method would be, without testing it > each time. > > 1. The test only needs to happen for overloaded methods. So, most of the > time, no change will occur. > > 2. Opcache may be able to help indicate which method will be executed, when > it is available. And perhaps, in some situations, it is possible to > determine which method will be tested as a priority, without having to test > all the time (in a loop, for example). > > function printId(User $user) { return a($user->id); } > function printId(int $userId) { printf($userId); } > > foreach ([1, 2, 3, 4, $userInstance] as $userId) { > printId($userId); > // First time: > // 1. Overload detected, but the best option is unknown; > // 2. Test option #1: rejected; > // 3. Test option #2: accepted and used; > // Next times: > // 1. Overload detected, the last occurrence was option #2, accepted > and used; > // 2. Option #2 can't be used for $userInstance, retest all options > (except #2). > } > > 3. Poorly typed functions or methods cannot be overloaded. > > function printId(User $user) { ... } > function printId($user) { ... } // Fatal error > > > Atenciosamente, > David Rodrigues > This was brought up four years ago (https://externals.io/message/93831) and you brought this up two years ago, but I don't think anything has changed to change the answer. The responses in the four-years-ago post contain some good explanations. Unless you have a draft implementation that fixes the issues mentioned I'm not sure it's productive to bring it up again. Best wishes, Matt --000000000000c8a46a05c0d2705a--