On Thu, Mar 8, 2012 at 10:03 AM, Arvids Godjuks <arvids.godj...@gmail.com>wrote:

> Hi Simon!
>
> 2012/3/8 Simon Schick <simonsimc...@googlemail.com>:
> > Hi Arvids,
> >
> > I pretty much like this idea as it's more strict. Let me say something
> > to the questions you pointed out here.
> >
> > 2012/3/7 Arvids Godjuks <arvids.godj...@gmail.com>:
> >> I realize that with scalars it's not that straight forward, but
> >> complicating things by adding an auto-cast syntax and so on is just
> >> ridiculous. Hints should stay, well, hints. The only problem we have
> >> is complications of accepting numerical strings or numbers as strings.
> >> And what to do with "null".
> >
> > I'd like to handle it the same way as it's handled with the classes
> > right now. If null is not the default-value you'll get an error when
> > you pass null in there.
> > One thing I'd like opened here: If you define a default-value
> > different than null, should you be able to pass null as well and the
> > compiler will use the default-value?
> >
> >> function a(bool $bool) {}
> >> a(10); // Kill your self against the wall - write a(true);
> >> If you define bool - use the damn bool!
> >
> > I like that. What should we do if this appears? As it's now - just
> > throw an "Catchable fatal error" and let the script blow-up? I would
> > go this far.
>
> I think "Catchable fatal error should" be fine and users are familiar
> with such mechanic because it already exists. Consistency, man,
> consistency :)
>
>
> >> I consider interchangeable only three cases:
> >> 1. Numerical string.
> >> 2. Integers and floats as strings.
> >> 3. Integer and string  0 1 as bool.
> >>
> >> Any other cases should error out.
> >
> > Until now I thought about the weak variable-types as a order ...
> > string, float, integer, Boolean.
> > All Boolean values are compatible be an integer (0 or 1) and all
> > integer are compatible to a float and so on. Do you think it's good to
> > have it this way? This would mean that you could also get a Boolean
> > true as string "1" ... I personally don't like that ... but I don't
> > know where to draw the strict-line.
> > Now think about that backwards. Can a "1" be passed as a parameter
> > that expects Boolean? If yes, I'd keep it consistent in both ways.
> >
> > Bye
> > Simon
>
> That's a good tricky question, I like it.
> Well, I think the lower should work just fine.
> function a(bool $int) {};
> a("1");
>
>
AFAIR Gustavo, Anthony and Nikic discussed on IRC, that maybe the best
solution for scalar type hints would be the unification of the scalar type
hints with the current implementation of zend_parse_parameters.
the built in php functions are "enforcing" the function signature via
parsing the parameters through this call.
so for example the above mentioned substr signature is substr ( string
$string , int $start [, int $length ] )
substr("foobar", "123"); // works like a charm
substr("foobar", 1.5); // works, no warning/notice, although we lose
precision here,
substr("foobar", "123 asd"); // Notice: A non well formed numeric value
encountered
substr("foo", "bar"); // Warning: substr() expects parameter 2 to be long,
string given

so if we would implement the scalar typehints in a way to map the signature
types to the zpp call, then that would mean that the scalar hints are
consistent across the built-in functions, the documentation, and the
dynamic nature of the language(as one could argue that the current/future
implementation of zend_parse_parameters is in line with the dynamic
casting/type juggling nature of php.

just my 2cents

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

Reply via email to