On Wed, Jun 26, 2013 at 4:48 PM, Johannes Schlüter
<johan...@schlueters.de> wrote:
> On Wed, 2013-06-26 at 16:40 +0200, Ferenc Kovacs wrote:
>
>> >
>> I think that the return typehints a bit easier topic than the input type
>> hinting(for scalars), because that affects the caller, while return type
>> hinting is more contained: you write the function, you put the return
>> typehint there, if the method tries to return something else, then your
>> code is at fault.
>> So even if we would allow return typehints for scalars that would only
>> affects those functions where the developer opts-in.
>
> So a function author doesn't trust himself and therefore we change the
> language syntax?
>
> johannes
>

All,


Thanks for the feedback so far.

I've added the typing for scalars as I thought it would be nice to
have them but if it's easier to start with supporting what we already
have for argument hinting then it would be a great win for the
language nonetheless.

To address the performance concern issues, I think the performance
issues should be very little, like a call to instanceof for example,
but I can't say for sure. Of course benchmarks for the actual
implementation will need to be made and a manual entry should note
that using this feature might have a performance impact if really
needed (as I would imagine in 15000 function calls, something that you
might see in todays frameworks it could have a more visible impact).

@johannes it's not about the author of the function doesn't trust
itself, it's about I'm writing a interface and I expect to receive a
array but someone returns a string or a single value.

That's why I've said that the feature is more about code quality that
new toys for developers. Those who opt-in for using this in interfaces
would guarantee that every implementation of their interface would be
consistent in return type, just like what we have today for arguments,
where you can guarantee that you'll have the type you need in your
method.

If the feedback will be positive for this, as it is right now, I would
also like to start working on a patch for this in 2-3 weeks maybe so
this is a early request for help for anyone that could point me out in
the right direction or champion this patch. I'll make another request
when I'll be ready to start working on the patch.


Best regards.
----
Florin Patan
https://github.com/dlsniper
http://www.linkedin.com/in/florinpatan

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to