On 28 February 2021 13:20:57 GMT, Eugene Sidelnyk <zsidel...@gmail.com>
wrote:
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.
https://habrastorage.org/webt/my/8t/in/my8tin97ukibw6ebh0cbaqhmv64.png
It's not to do with your mail client or formatting, the mailing list
strips all attachments. Screenshots of text are probably the worst way
of sharing a quote from something anyway.
I don't know what the rest of the article is like, but that quote makes
a pretty poor case for overloading.
It has very little to do with OOP - SmallTalk, where OO was invented,
doesn't have it, but plenty of non-OO languages do. There is some
relationship to polymorphism, in that you can consider two classes with
the same method name to be overloading that method name based on the
type of "$this"; but in that case PHP does have it.
If anything, overloading on the types of multiple parameters is
something I'd associate more with Functional Programming, where you
might have multiple overloads for a global function like add(x, y),
without them being "owned by" a particular type.
The example given of content(File) vs content(File, Charset) is also not
great, because it can be achieved in any language with optional
parameters, which does include PHP. In some languages, using
overloading would save an if check at run-time, because the compiler
would select the correct overload, but PHP's method despatching and type
checking are all done at run-time anyway.
With union types and named parameters, a lot of cases where overloading
would be used in C# or Java can be expressed in a slightly different
form in modern PHP. It would sometimes be nice to have multiple
constructors, but named constructors are more flexible than overloading
by type (e.g. Foo::fromName(string $name) and Foo::fromCode(string
$code)), and static methods provide a reasonable stand-in for those.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php