Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113326 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 45382 invoked from network); 28 Feb 2021 13:17:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Feb 2021 13:17:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 48AA21804F2 for ; Sun, 28 Feb 2021 05:07:16 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail.apserver.co.uk (server2.alteredperspective.co.uk [85.119.82.103]) by php-smtp4.php.net (Postfix) with ESMTP for ; Sun, 28 Feb 2021 05:07:15 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mail.apserver.co.uk (Postfix) with ESMTP id 4290E4F4064; Sun, 28 Feb 2021 13:06:03 +0000 (GMT) Received: from mail.apserver.co.uk ([127.0.0.1]) by localhost (server2.alteredperspective.co.uk [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 1VnsmHwIywrr; Sun, 28 Feb 2021 13:06:01 +0000 (GMT) Received: from [192.168.0.7] (cpc113422-maid7-2-0-cust493.20-1.cable.virginm.net [86.18.185.238]) by mail.apserver.co.uk (Postfix) with ESMTPA id 945BC4F4061; Sun, 28 Feb 2021 13:06:01 +0000 (GMT) To: Eugene Sidelnyk , PHP Internals References: Message-ID: Date: Sun, 28 Feb 2021 13:07:05 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] Methods Overloading in PHP From: php.lists@allenjb.me.uk (AllenJB) On 28/02/2021 12:49, Eugene Sidelnyk wrote: > Hi there! > I faced a lack of methods overloading in PHP once again and would like to > ask will it be implemented at some point? > As well, I want you to show some pros and cons which you see in this > feature. > > Here're some thoughts about this by Yegor Bugayenko: It looks like your message is missing at least a link. A quick search did however turn up a tweet where Yego suggests it's a code smell (which basically echos my thoughts below): https://twitter.com/yegor256/status/932701585339240449 A quick search shows the most recent discussion on method overloading here appears to be: https://externals.io/message/104073 The big problem with implementing method overloading in PHP is its typing system. It might be possible to implement it in certain cases where types are strictly defined for all parameters and return values, but I suspect there would still be issues over scalar types (particularly int/float) and union types. My personal opinion is that method overloading is unnecessary, and can be detrimental to code readability when not used carefully. Without it I think developers are forced to name methods that do similar things more concisely, while when it's available they're more likely to create a "single" generically named, overloaded method whose behavior can differ depending on the inputs.