PHP: Ambiguous Function Names

I am new to php and I have seen a rather ambiguous convention on the name of functions in php and it bothers me as I regularly forget function names. I suppose I should give you an example.

If the function for encoding htmlentities , then why is it the opposite with the name html_entitiy_decode , and not something like entitiesdecode or one that is closer to htmlentities .

There are also corresponding function names, but I think php does not have a consistent approach to naming its functions.

Any ideas because it's hard for me to remember function names. Thanks

+6
php
source share
4 answers

No, PHP really does not have a consistent approach to function names - this is mainly for two reasons:

  • Historical reasons: after functions were released with these names, they cannot be changed
  • Extensions / libraries: PHP is a "sticky" language that includes several external libraries and often uses the names of the functions of these libraries, which are not necessarily consistent.

Fortunately, the PHP developer community is aware of this and is trying not to repeat this error now when they are developing new functions, but most likely all of this will remain the same for the old functions.


The best you can do is accept one naming convention for your classes / functions / methods / variables and respect it in your projects; it will already be a good start.

+9
source share

There are several related question and answer in the PHP FAQ on parameter order :

I can’t remember the order of the parameters of the PHP functions, are they random?

PHP is a glue that brings together hundreds of external libraries, so sometimes it gets messy. However, a simple rule of thumb is as follows: Array function parameters are ordered as “needle, haystacks”, while String functions are opposite, therefore “haystacks, needle”.

The first sentence of the answer can also be applied to function naming.

For your own functions, review the User Names Guide> and / or review the following encoding rules, such as Zend or PEAR .

+3
source share

I am afraid this is a problem with PHP that you will have to live with. You can wrap these “unnamed” functions with your own, but this will obviously make calling these functions more expensive.

+2
source share

I would give a simple answer, the fact is that this is due to compatibility. A function once defined with a name cannot be canceled because it has been used in thousands of projects and in the core of the language, as well as in the pear and beak. Thanks

0
source share

All Articles