Re: function overloading
| From: | Quim Calpe | Date: | Wed, 16 Nov 2016 09:32:53 +0000 |
| Subject: | Re: function overloading | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96909@lists.php.net to get a copy of this message | ||
On Tue, Nov 15, 2016 at 10:33 PM, Alice Wonder <alice@librelamp.com> wrote:
> On 11/15/2016 08:13 AM, Dominic Grostate wrote:
>
>> I think this may have been discussed before, but I was largely dismissed
>> because no one though it would be possible to implement.
>>
>> However assuming it is possible, what is the general feeling towards
>> function overloading, as seen in C# and Java?
>>
>
> *snip*
>
> I don't understand what problem it actually solves.
>
> For me, my short term memory isn't very good and some text editors let me
> type a function name and they show the arguments with symantic arguments
> names and that is really beneficial becomes sometimes I forget whether
> $needle comes before $haystack or vice versa.
>
> Those hints are harder to do with function overloading because the editor
> has to then also guess how the function is being used which the editor can
> not easily do.
>
> It just seems to make things more difficult without solving a problem. To
> me anyway.
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
a typical use case would be
class EventHandler {
public function handle(ProductCreated $event) {
...
}
public function handle(ProductNameChanged $event) {
...
}
}
vs what's currently being done:
class EventHandler {
public function handleProductCreated(ProductCreated $event) {
...
}
public function handleProductNameChanged(ProductNameChanged $event) {
...
}
}
or even:
class EventHandler {
public function handle(Event $event) {
if ($event instanceof ProductCreated) {
...
} elseif ($event instanceof ProductNameChanged) {
...
}
}
}
Quim