Hi François,
> -----Ursprüngliche Nachricht-----
> Von: François Laupretre [mailto:[email protected]]
> Gesendet: Donnerstag, 12. Februar 2015 18:01
> An: 'Robert Stoll'; 'Nikita Nefedov'; 'Andrea Faulds'
> Cc: 'Pavel Kouřil'; 'PHP Internals'
> Betreff: RE: [PHP-DEV] [VOTE] Scalar Type Hints
>
> Hi Robert,
>
> > De : Robert Stoll [mailto:[email protected]]
> >
> > There are several programming languages which do support dynamic
> > typing and method overloading somehow (Clojure, Erlang, Prolog, Cecil
> > and certainly more). Most of them use a multi-method approach and I
> > think if PHP would introduce function/method overloading, then such an
> > approach would be appropriate. Right now, I need to implement the
> > dynamic dispatching quasi myself which might be more verbose but is
> > also more cumbersome (and uglier IMO). Consider the following (fictional
> > example):
>
> We all agree on the interest of polymorphism on object classes, even if your
> example could be solved with specialized
> logger classes, but the question was about polymorphism on different scalar
> types, which is much more problematic in PHP,
> even using strict scalar typing.
>
> Cheers
>
> François
OK, maybe I went a little bit off topic due to the booted discussion about
method overloading which did not cover all aspects IMO. So back to scalar type
hints:
I do not really see how num would be a problem or polymorphism in general. I am
not really aware of memory management of PHP but I guess it is not optimised
for fixed-sized integers or is it?
If not, then it does not really matter whether a parameter holds an int, a
float or a BigInt, allocation is dynamic anyway I suppose. Or what problems do
you see here?
Maybe you are referring to Pavel's example:
> the issue I see with it is that bar() requires float, but foo() just number
> and doesn't convert it to the required type. The most unpredictable thing is
> that it will work half of the time and half of the time it will just throw
> errors
The same applies for the following code
class Foo{}
class Bar{}
function foo(Foo foo){
bar($foo);
}
function bar(Bar bar){
//..
}
and we still agree upon that polymorphism is the right way to go since it
allows more expressive code with a certain "safety". If you want full
flexibility, then rely on dynamic typing only and if you want some safety then
use type hints. I do not see a special case here - polymorphism for scalar
types is nothing new
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php