39 Followers
61 Following
65 Posts

What are the most common tools (saas or installed) that are used with #PHP application and component.

composer, OK. git, OK.

And then?

https://www.exakat.io/en/common-services-with-php-application/

Avoid comparisons with #PHP get_class()

get_class() should be replaced with the instanceof operator to check the class of an object.

instanceof actually resolves the name, using the local namespace and aliases. It is also faster.

https://exakat.readthedocs.io/en/latest/Reference/Rules/Structures/UseInstanceof.html

1.2.74. Avoid get_class() — Exakat 1 documentation

Lone Blocks In #PHP

Grouped code without a commanding structure is useless and may be removed.

Most often, it is a ruin from a previous flow control instruction, whose condition was removed or commented. They should be removed.

https://exakat.readthedocs.io/en/latest/Reference/Rules/Structures/LoneBlock.html

1.2.638. Lone Blocks — Exakat 1 documentation

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().

#phptip #phptrick

#PHP preg_match_all() is faster without the 3rd $matches argument, and then, it can be replaced by preg_match(), with another speed bump.

#phptip #phptrick

#PHP : here are some irreconciliable differences between is_a() and instanceof.

#phptip #phptrick

For some reason, instanceof doesn't accept the :: operator : nor static method, nor class constants : only static properties.

https://3v4l.org/OEpgo

OEpgo - created on 3v4l.org

View the output of this script on 3v4l.org: the online PHP shell with 250+ PHP versions

It is possible to escape argument typing by using union type in #PHP 8.0+. Keep the compatible type, and add any other; repeat.

Probably a necessary evil of union types.

#phptip #phptrick