Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to find a way of classifying different types of PHP functions. For example that fopen, fwrite, fclose and so on are all part of IO, and the MySQL functions and MySQLi class is all for mysql related things but something more automatic was wondering if there is some sort of function class mapping in PHP

share|improve this question

1 Answer 1

In many languages, classes/methods/functions are organized into namespaces, which may be presented as a tree (namespace A.B and namespace A.C are logically grouped, while B.D is not not).

PHP recently introduced namespaces for custom code, but the PHP core set of functions was always a mess, and will stay a mess: it won't be organized into namespaces, because it would break all existent PHP code. Don't expect any organization from a language where functions are totally inconsistent when it comes to their names or the order of arguments.

On the other hand, PHP documentation is excellent, and it helps you understanding how functions are grouped. For example, if I take the two groups you quoted in your question, you'll find the functions related to strings on a dedicated page, and MySQL functions on another one. Those are conveniently organized into a tree: MySQL-related documentation is inside Vendor Specific Database Extensions section, which is in turn inside Database Extensions.


Note: be careful! The list of functions tell you what functions are in the same group, but doesn't tell the relations with other groups. For example, it won't tell that when manipulating strings such as user input, you should use Unicode variants, and it won't tell that instead of accessing the MySQL database directly, you should use PDO.

share|improve this answer
    
What is your definition of a "normal language"? There are many languages without namespaces. –  johannes May 10 '13 at 12:59
1  
@johannes: PHP is the only language I know of that exposes such an enormous technical debt due to organic growth while at the same time being so intensely popular. No other popular language drags this much cruft around, and in this sense, the notion that PHP is not "normal" is absolutely justified IMO. –  tdammers May 10 '13 at 16:04
    
@johannes: agreed, there may be normal languages which lack namespaces (or modules, or anything similar to namespaces). I edited the question to correct this. This being said, the previous comment by tdammers also explains why PHP can hardly be qualified as normal when it comes to organizing functions. –  MainMa May 10 '13 at 16:39
    
Well, yes to some degree this is true, while a majority of of the functions from the core PHP distribution is prefixed by their respective module's name, the remaining ones might be called "core functions" to some degree it can be hard to categorize further (i.e. are explode/implode array functions or string functions?) –  johannes May 11 '13 at 0:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.