Re: [PHP-DEV] int|float for DateTime::setTimestamp

2024-02-13 Thread Ayesh Karunaratne
>
> just like the constructor accepts
> new DateTime("@0.123456"); // 1970-01-01 00:00:00.123456
> new DateTime("@".microtime(true));
>
> IMO setTimestamp should accept the same:
> $dt->setTimestamp(0.123456); // 1970-01-01 00:00:00.123456
> $dt->setTimestamp(microtime(true));
>
> Can we change setTimestamp to accept int|float?
> made a PR https://github.com/php/php-src/pull/13383

You are probably already aware, but PHP 8.4 will have a new
`DateTime::get/setMicroseconds` method[^1][^2] that accepts an integer
microsecond value.

That said, I personally think it makes sense to accept float values
for fractions of seconds, but changing the parameter type WILL be be a
BC break because all subclasses extending `setTimestamp` will not be
compatible unless they are changed to `int|float` or wider.


[^1]: 
https://github.com/php/php-src/commit/0016b3085cf06e8a189ecc53c31697e3a108dbdd
[^2]: https://php.watch/versions/8.4/date-datetime-get-setMicroseconds

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



[PHP-DEV] [Discussion] Thoughts on casting to null

2024-02-13 Thread Robert Landers
Hello Internals,

Today, I was working with a library (ReVolt) that throws if a callback
returns something other than null (why it doesn't ignore the value, I
don't know, maybe I'll file an issue). I discovered the topic of this
email after trying to be simple:

EventLoop::repeat($pingInterval, $client->ping(...));

Where `ping()` will return a bool which triggers an error since it
returns something. I thought to myself, cool, I'll just cast the
result to null and everything will be fine:

EventLoop::repeat($pingInterval, fn() => (null) $client->ping());

However, this isn't allowed and fails with a parse error.

I won't be the first to say this, at first glance, casting to null
sounds silly, but short arrow functions must always return something,
by design. That's when casting to null makes any sense at all (that I
can think of): you want to write a succinct, short function but
guarantee the result is discarded. Instead, if you really must use a
short array function, you have to do something even weirder:

EventLoop::repeat($pingInterval, fn() => $client->ping() ? null : null);

I assume casting to null was discussed previously (at some point,
though I didn't see anything), but what are your thoughts? Is this
something that even makes sense? I'll admit, I've never tried casting
to null before, but I had assumed it would "just work" and was
slightly surprised that it didn't.

Robert Landers
Software Engineer
Utrecht NL

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



[PHP-DEV] int|float for DateTime::setTimestamp

2024-02-13 Thread Hans Henrik Bergan
just like the constructor accepts
new DateTime("@0.123456"); // 1970-01-01 00:00:00.123456
new DateTime("@".microtime(true));

IMO setTimestamp should accept the same:
$dt->setTimestamp(0.123456); // 1970-01-01 00:00:00.123456
$dt->setTimestamp(microtime(true));

Can we change setTimestamp to accept int|float?
made a PR https://github.com/php/php-src/pull/13383


[PHP-DEV] [RFC] [Vote] Opt-in DOM spec-compliance

2024-02-13 Thread Niels Dossche
Hi internals

I'm starting the vote on my RFC "Opt-in DOM spec-compliance".
Voting will run until the 27th of February 21:00 GMT+1.

RFC link: https://wiki.php.net/rfc/opt_in_dom_spec_compliance
Discussion: https://externals.io/message/122169
Pre-RFC pitch: https://externals.io/message/122048

Kind regards
Niels

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



[PHP-DEV] Test Email — Ignore

2024-02-13 Thread Derick Rethans
(We're going to need to move the lists servers, and just trying to 
figure out how email gets currently delivered)

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