Le samedi 24 mai 2025, 19:42:34 heure d’été d’Europe centrale Niels Dossche a 
écrit :
> In my opinion, the return type should not be nullable.
> Returning NULL when the platform (or PHP on that platform) doesn't support 
> getting this information is an anti-pattern.
> Instead, availability of the necessary functionality should be checked at 
> configure time and the function should be made conditionally available.
> That way, the return type can just be "int".

I strongly disagree here, having PHP function not always available is a mess, 
and forces function_exists checks all over the code. It feels archaic.

I get the idea of throwing instead of returning NULL for errors, but the idea 
behind the nullable return is to get this nice thing:
$cpus = num_available_cpus() ?? 1;

If the function throws on error, this gets more convoluted. Maybe it can be 
replaced by a parameter $defaultNumber and only throw when no default is given?

Regarding the CPUs available for PHP or total number discussion, maybe that 
justifies the "available" keyword in the name and it returns only those 
available to PHP, and we add a second function for total number?
Or as some people suggested in the PR, we add a namespaced class with methods 
for this.

Côme

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to