Here is the top 100 PHP classes : it is the list of the most often used PHP native classes.
The classes are ranked in order of project frequency. In a corpus of 2500 OSS projects, the classes (and a few interfaces) were detected. They may be used by instantiation, as a type hint (property, argument, function, instanceof), by extension, by implementation, or with the :: operator. One occurrence per project is enough, and they are then not differentiated.
For example, almost 46% projects use the Exception class. That is used on average 26 times, but may clock up to 450 usage in the same project.
Click on the link to go to the documentation. Some extra insights are at the bottom of the top 100.
Top 100 insights
Here are some extra insights.
-
The most commonly use PHP class is used in less than 50% of the projects. For comparison, a commonly used function is used in 81% of projects.
-
The most commonly used PHP class are exceptions. Most often is for catching them when they are thrown by some other part of the software (component, extension, etc.), are more rarely, to throw them.
-
The Exception class usage may be very ambiguous : when it is extended, it tends to hide its usage by giving it another name; On the other hand, catching Exception as a catch-all (sic) makes it a very common class.
-
Stdclass usage is a good 8th. Compared to the others, it is a hidden class. For example, the result of json_decode() or (object) is a Stdclass, without ever mentioning it.
-
The same could apply to Closure and Generator.
-
-
SPL and the iterators are still very underused
-
JsonException usage levels shows that it is not a default option.
-
No one should use __php_incomplete_class… ever.
Challenges
If you are learning PHP, it is a good idea to review the 100 classes ranked here : they are the classes you’ll find the most often when landing on a coding team. They are not the only ones, but you’ll be better equiped by learning them.