>
> I believe returning null in those situations makes the most intuative
> sense, yes.



No offense, but how can casting semantics different from those already used
in implicit casting be intuitive?

    function a(int $x) { var_export($x); }
    function b(?int $x) { var_export($x); }

    a("123"); // 123
    a(null); // TypeError
    a("abc"); // TypeError

    b("123"); // 123
    b(null); // NULL
    b("abc"); // TypeError

IMO, the only reasonable choice is therefore:

    (int) "123"; // 123
    (int) null; // TypeError
    (int) "abc"; // TypeError

    (?int) "123"; // 123
    (?int) null; // NULL
    (?int) "abc"; // TypeError

At least, if we want to fix the current behaviour, and not introduce
another inconsistency.
In other words, *strictly apply to explicit casting the rules of implicit
casting when strict_types is disabled*.

--
Ben

Reply via email to