Hi Walter,

On Tue, May 12, 2015 at 11:25 AM, Walter Parker <walt...@gmail.com> wrote:

> You know, given how worried you seem to be about this issue, could you
> booby trap your so that if the developers use the wrong type (int vs.
> string) the program throws fatal errors with nasty error messages that
> explain how much trouble the developer is in at the userland code level?
>
> While I like the of protecting idiot developers from themselves, I'm still
> not sure that this isn't a half solutions that just hide the pieces of the
> problem that it doesn't solve.
>
> I don't think we can solve the problem of developers not writing code
> correctly or QA would mostly be out of job (instead of being a growth
> segment).
>
> How about a full type system that would make Java programmer scream? I'm
> sure with a bit of thought we can make one heavier than Java.
>

Java is not PHP.
Java does not have 32 bit int on 32 bit machines, 64 bit int on 64 bit
machine.
Java has concrete byte, short, int, long type. It's whole different story.



BTW, I noticed that mt_rand() behavior has changed to raise E_WARNING for
too large numbers.
This is good change because PHP is known to generate very weak random
number with invalid
min/max.

[yohgaki@dev ~]$ php-5.6 -r "var_dump(mt_rand(222,
'99999999999999999999999'));"
int(115282844144104926)
[yohgaki@dev ~]$ php-7.0 -r "var_dump(mt_rand(222,
'99999999999999999999999'));"

Warning: mt_rand() expects parameter 2 to be integer, string given in
Command line code on line 1
NULL

This behavior is much better. I mean E_WARNING and return NULL from
function is
much easier than dealing with E_RECOVERBLE_ERROR.

Strict mode may stay as it is, but shouldn't we have consistent behavior?
Internal function raises E_WARNING for too large int while user function
raises E_RECOVERBLE_ERROR
does not make much sense.

Regards,

P.S.
With strict_types=1, mt_rand() gives

Fatal error: mt_rand() expects parameter 2 to be integer, string given in
/home/yohgaki/t.php on line 3


--
Yasuo Ohgaki
yohg...@ohgaki.net

Reply via email to