A small update on the blogpost about PHP’s internal function usages: https://www.adayinthelifeof.nl/2014/07/25/internal-php-function-usage/
A lot of people are asking about functions like isset, empty, print, echo etc, as they are not present in the current result list. The thing is, is that these are not really functions, but language constructs. This means that PHP treats them a bit different than normal functions, and this results sometimes in seemingly “strange” behaviour when trying to use them like regular functions:
will not work, while the following does:
In any case, I’ve revisited the results a bit, and added some of these constructs to the list: echo, empty, eval, isset, print, unset and even yield. As with the first attempt, I’ve taken some of the peaks out of the equation: every repository with over 1000 of the same functions:
https://github.com/e107inc/e107 => define - 7000
https://github.com/eryx/php-framework-benchmark => empty - 5824
https://github.com/eryx/php-framework-benchmark => count - 5052
https://github.com/eryx/php-framework-benchmark => isset - 16320
https://github.com/eryx/php-framework-benchmark => sprintf - 5948
https://github.com/opencart/opencart => isset - 5225
https://github.com/googleads/googleads-php-lib => class_exists - 35648
https://github.com/s9y/Serendipity => define - 74004
So without these, the new results, the top 22:
The rest of the results can be found here.
Some interesting facts:
- isset() is winning by a landslide. There are in the almost 1000 repositories checked, twice as much calls to isset() than to the number two function (echo).
- After some fine-tuning and tweaking, the top-3 are all language construct, the first “real” function substr() is #4, and count() #5. These two have swapped places from the last check because of some repositories with a unreasonable high number of count() statements.
- echo (#2) is used more than print (#42) with a ratio of almost 5:1.
- In order, the most calls are made to: is_array, is_string, is_null, is_object, is_numeric, is_bool, is_callable, is_resource, is_scalar, is_a, is_integer, is_double, is_long.
- 529 times eval() is called :(
- 71 times a generator is generated with yield.