Re: [PHP-DEV] Two new functions array_first() and array_last()

2023-10-14 Thread Saki Takamachi
I came up with the idea of ​​using a signature like array_filter(), and when a callback is passed, "return the first/last element that matches the condition" and "return null if there is no match." The downside to this idea is the loss of simplicity. So I'll leave it up to you whether you want

Re: [PHP-DEV] Two new functions array_first() and array_last()

2023-10-14 Thread Ayesh Karunaratne
> > PHP lacks two very basic functions for working with arrays: > > - array_first() returning the first element of an array (or null) > - array_last() returning the last element of the array (or null) > > While PHP has functions that return the first and last keys, > array_key_first() and array_key

Re: [PHP-DEV] Two new functions array_first() and array_last()

2023-10-14 Thread Saki Takamachi
Hi, David Many times I've seen reset() used to meet this requirement. I support this, not only from a side effect standpoint, but also from a readability standpoint. I would also like to add the opinion that it is better because it is simpler than the function name in the original RFC that is b

Re: [PHP-DEV] Better name for method Randomizer::nextFloat()

2023-10-14 Thread tag Knife
On Sat, 14 Oct 2023 at 18:48, David Grudl wrote: > > A) The problem with nextFloat() is that the name creates a false > expectation. Take a look at the following code: > ``` > $randomizer = new \Random\Randomizer(); > $a = $randomizer->getFloat(100, 200); // number between 100..200 > $b = $random

Re: [PHP-DEV] Two new functions array_first() and array_last()

2023-10-14 Thread Ben Ramsey
> On Oct 14, 2023, at 16:30, Nikita Popov wrote: > > On Sat, Oct 14, 2023, at 20:00, David Grudl wrote: >> PHP lacks two very basic functions for working with arrays: >> >> - array_first() returning the first element of an array (or null) >> - array_last() returning the last element of the arra

Re: [PHP-DEV] Why did fibers get added to php core over something more fleshed out like swoole?

2023-10-14 Thread Rowan Tommins
On 13 October 2023 01:59:59 BST, Lanre Waju wrote: > It sometimes seems as though certain choices may not > align with the best interests of the PHP community. I would > appreciate it if you could provide insights into why this > might not be the case. Leaving aside the specific examples for a mo

Re: [PHP-DEV] Two new functions array_first() and array_last()

2023-10-14 Thread Nikita Popov
On Sat, Oct 14, 2023, at 20:00, David Grudl wrote: > PHP lacks two very basic functions for working with arrays: > > - array_first() returning the first element of an array (or null) > - array_last() returning the last element of the array (or null) > > While PHP has functions that return the fir

[PHP-DEV] Two new functions array_first() and array_last()

2023-10-14 Thread David Grudl
PHP lacks two very basic functions for working with arrays: - array_first() returning the first element of an array (or null) - array_last() returning the last element of the array (or null) While PHP has functions that return the first and last keys, array_key_first() and array_key_last(), it do

[PHP-DEV] Better name for method Randomizer::nextFloat()

2023-10-14 Thread David Grudl
I would like to suggest changing the name or removing the nextFloat() method, which is coming to PHP 8.3. The Random\Randomizer class will have two new methods for generating random numbers: - getFloat($min, $max [, $boundary]) - nextFloat() Now please try to guess what these methods do and, more

[PHP-DEV] Better name for method Randomizer::nextFloat()

2023-10-14 Thread David Grudl
I would like to suggest changing the name or removing the nextFloat() method, which is coming to PHP 8.3. The Random\Randomizer class will have two new methods for generating random numbers: - getFloat($min, $max [, $boundary]) - nextFloat() Now please try to guess what these methods do and, more

Re: [PHP-DEV] DOMXPath / XSLTProcessor function callbacks

2023-10-14 Thread Niels Dossche
Hi Tim On 10/14/23 14:42, Tim Düsterhus wrote: > Hi > > On 10/14/23 13:54, Niels Dossche wrote: >>> (a) Call ucfirst(), but not strtoupper() >>> (b) Call both >> >> You can call both, it's additive. >> > > Okay, for your suggestion (1) the following would work then? > > // Register all native P

Re: [PHP-DEV] DOMXPath / XSLTProcessor function callbacks

2023-10-14 Thread Tim Düsterhus
Hi On 10/14/23 13:54, Niels Dossche wrote: (a) Call ucfirst(), but not strtoupper() (b) Call both You can call both, it's additive. Okay, for your suggestion (1) the following would work then? // Register all native PHP functions. $xpath->registerPHPFunctions(null); // Register additional

Re: [PHP-DEV] DOMXPath / XSLTProcessor function callbacks

2023-10-14 Thread Niels Dossche
Hi Tim On 10/14/23 12:30, Tim Düsterhus wrote: > Hi > > On 10/13/23 00:39, Niels Dossche wrote: >> Please let me know your thoughts. > > What does calling ->registerPHPFunctions() do when it's called more than > once? Will the existing allow-list be overwritten or amended? > > i.e. > > $xpath

Re: [PHP-DEV] [Round] Change the edge case of Round()

2023-10-14 Thread Tim Düsterhus
Hi On 10/13/23 11:59, Saki Takamachi wrote: For example, `0.285` is internally `0.28498`. Should this be considered an edge case? Or is it not an edge case? Regarding this issue, in 2008, the following RFC adopted the policy that `0.285` is considered an edge case''. https://wiki

Re: [PHP-DEV] DOMXPath / XSLTProcessor function callbacks

2023-10-14 Thread Tim Düsterhus
Hi On 10/13/23 00:39, Niels Dossche wrote: Please let me know your thoughts. What does calling ->registerPHPFunctions() do when it's called more than once? Will the existing allow-list be overwritten or amended? i.e. $xpath->registerPHPFunctions([ 'strtoupper', ]); $xpath->registerPHPFun