Re: Methods Overloading in PHP

From: Date: Sun, 28 Feb 2021 13:20:57 +0000
Subject: Re: Methods Overloading in PHP
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-113327@lists.php.net to get a copy of this message
> It looks like your message is missing at least a link Sorry, I am using gmail and have attached an image which you probably can't see. ![excerpt from book]( https://habrastorage.org/webt/my/8t/in/my8tin97ukibw6ebh0cbaqhmv64.png) On Sun, Feb 28, 2021 at 3:07 PM AllenJB <php.lists@allenjb.me.uk> wrote: > > 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. > >

« previous php.internals (#113327) next »