On 24/02/12 00:36, Kris Craig wrote:
> Hmm that's a fascinating idea!  So, and please correct me if I'm
> wrong, you're saying that it might be a better approach to determine
> strict vs. dynamic typing on a per file or function basis instead of
> on a per stack basis?  In other words, blah.php could contain two
> functions, one using strict typing and the other using traditional
> dynamic typing?
Yes. Two functions in the same file with different conventions may be a
strange use case, I'd expect differences to come from eg. using two
libraries, each with different typing.


> Theoretically, I think that approach could work.  Perhaps we'd have it
> specified in the function declaration itself; i.e. "function whatever(
> $text, $number )" would be a traditional, dynamically-typed PHP
> function, whereas "strict function whatever( string $text, int $number
> )" would use strict typing.
I'm not keen with that syntax, but that could be discussed. I remember
something similar was already mentioned in another types thread, with
ideasl like string! or string? to mark the types as strict or weak.


> The obvious question then would be, what if dynamic function A makes a
> call to dynamic function B, passing to it a dynamically-typed
> variable?  There are three viable approaches that come to mind:  This
> count not be allowed; this could be allowed but only if the variables
> being passed to function B are cast first (i.e. B( (string) $text,
> (int) $number );); or, this could be allowed without casting, in which
> case PHP would attempt to pass the variable and then throw an
> exception if it cannot be parsed as the required type.  Personally, my
> vote would be for Option 2.
I was envisioning it just as an interface for the call. Thus, if funtion
A used strict or dynamic types would be irrelevant. You seem to be
bringing up another option however, which is that funcion A could
specify the behavior on functions it calls.
It can look appealing, but I don't think that's desirable. After all,
it's the callee interface what is important, not the kind of caller (you
could have a setting to force an stricter behavior, but that seems more
appropiate for an extension, like xdebug scream option).


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

Reply via email to