• Hii,
    I’m trying to learn wordpress core and when I saw the compat.php file in wp-include I didn’t understand why they checking for functions that exist in php and then if it not defined they define it. It does not make any sense to me. Why trying to write function that already exist in php core and why even to check if those function exist in the first place, if they suppose to be (I am talking about functions like mb_substr() ).

    I would appreciate any help.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Dion

    (@diondesigns)

    The comment at the top of the file is self-explanatory:

    WordPress implementation for PHP functions either missing from older PHP versions or not included by default.

    You mentioned mb_substr(). The function in compat.php allows WordPress to use the mb_substr() function in its core. Those PHP installations who do not have the PHP mbstring extension installed will use the function in compat.php, and those with mbstring installed will use the (orders of magnitude faster) native function.

    Having said this, I’m unsure why there is a JSON class. The JSON extension was bundled in the core starting with PHP 5.2.1, so there is no need for external JSON functions since the PHP requirement for WordPress is 5.2.4 (should be 5.3, but I digress). I also think that any plugin/theme developer using JSON functions is going to check the PHP version themselves before attempting to use JSON_PRETTY_PRINT, so that’s not needed either.

    Dion – maybe you can query the JSON requirement further? If you’re confident of your answer, maybe add it straight onto Trac as something for the Core guys to look at.

    David.

    Dion

    (@diondesigns)

    I’m confident of my answer, but to be honest, cleaning up compat.php seems like a waste of time since it’s a small and mostly useless file. Had we been talking about wp-db.php (the file which IMO is in the poorest shape in the entire WP distribution package), I might have a little more to say. ??

    Raise that then Dion.

    David.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Why need compat.php’ is closed to new replies.