Re: Allow sleep() to accept non-integer values

From: Date: Tue, 11 Aug 2020 12:13:13 +0000
Subject: Re: Allow sleep() to accept non-integer values
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-111458@lists.php.net to get a copy of this message
Björn Larsson wrote: > Given this unexpected behaviour, one could almost see it as a bug. This isn't a suddenly noticed new bug. That code has worked like that since the sleep function was committed twenty-two years ago or for five years since the release of PHP 7 and the weak/strict RFC continued the "if you don't want float -> int conversions, use strict mode" choice. There are quite a few functions in PHP that take int parameters, that have this behaviour. These could all be 'fixed' by people using strict mode, and you could make a good argument for making strict mode the default, but it's probably a bit late in the 8.0 release cycle for that, and it _might_ be a little contentious. I agree that the PHP standard library is not as good as it could be, but tweaking it piece-by-piece is not a good way of fixing it. Doing it like that would lead to subtle BC breaks that are not obvious. G.P.B. wrote: > I'd rather see the failure condition changed to reject 0 or add a > E_NOTICE/E_WARNING if 0 is passed as this has questionable semantics. sleep(0) is a useful thing to do in some circumstances. It has the same effect as Thread.yield() in Java. Or in English, it allows a process to say "Hello OS scheduler, I don't want to sleep right now, but if there are any other threads that are waiting for their turn, now is a great time to suspend my execution, as I'm not in the middle of anything, otherwise I'll keep processing." Again, yes we need a better way of evolving the core libraries. But tweaking it on a function by function basis is not a good way of doing that. cheers Dan Ack

« previous php.internals (#111458) next »