TIL that #PHP has a dedicated function to calculate exp($x) - 1.
You can save quite some typing by using expm1($x);
It means exponential minus one.
One of my favorite math joke is to tell people that 'Some infinites are larger than others' (Which is true, see https://cantorsparadise.com/why-some-infinities-are-larger-than-others-fc26863b872f).
At the same time, in #PHP, infinite is accessible to anyone.
I just watched a conference, where the speaker complained that, for no good reason, #PHP concatenation operator is comma ','
This is definitely not the most popular concatenation operator, yet it kinda happens in one situation. Can you name it?
Since #PHP 7.4, there are numeric separators, to make numbers more readable.
They are only for hard-coded literals, so what do you do if you have stored them in a string ? π
https://www.php.net/manual/en/language.types.integer.php#language.types.integer.syntax
Here is a case where the difference between a #PHP constant and a name (class, function, method...) is fuzzy.
There is, at least, another case. Which one?
With #PHP 8.1, it is possible to add (...) (parenthesis, three dots, parenthesis) as you like, between the method name and the arguments. This is fun!
The last command is also possible, but requires a bit of brain twisting. How to make it work?
#PHP allows to call any method statically, when within the same class. Here, self::foo() is a valid call (don't try this outside the same class...).
This is needed to call parent:: methods, without $this.
Question : what does $this contains in the method foo(), called statically ?
The object or null ?
TIL that #PHP also supports attributes with enum, interfaces, traits and enum's cases.
https://kirschbaumdevelopment.com/insights/extending-php-enums-with-attributes
Today, I realized that the short assignment operators are the bitwise type, not the logical ones.
This is a 0, while I expected true.
There is not ||= nor &&= operator.
Could I ask for one in #PHP 8.3?
https://www.php.net/manual/en/language.operators.assignment.php
How to remove a value in a #PHP array, six methods.
https://www.exakat.io/en/removing-a-value-in-an-array-six-methods/
Yesterday, I learnt that #PHP generators can also be used directly with the ellipsis operator.
Yield are collected in an array, and then spread.
This syntax ignores return statements. If you don't need the spread, use iterator_to_array().
[Repost du blog]
exakat, static analysis for PHP (@exakat) #phptip #phptrick
https://warriordudimanche.net/article1807/6400ff22c835d
On en apprend tous les jours...
```
#php #CodeDeveloppement #astuce #phptrick #phptip
#PHP : here are some irreconciliable differences between is_a() and instanceof.
For some reason, instanceof doesn't accept the :: operator : nor static method, nor class constants : only static properties.