Title: Why need compat.php
Last modified: August 31, 2016

---

# Why need compat.php

 *  [orrafgin](https://wordpress.org/support/users/orrafgin/)
 * (@orrafgin)
 * [10 years ago](https://wordpress.org/support/topic/why-need-compatphp/)
 * 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](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [10 years ago](https://wordpress.org/support/topic/why-need-compatphp/#post-7358589)
 * 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.
 *  [David Artiss](https://wordpress.org/support/users/dartiss/)
 * (@dartiss)
 * [10 years ago](https://wordpress.org/support/topic/why-need-compatphp/#post-7358672)
 * 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](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [10 years ago](https://wordpress.org/support/topic/why-need-compatphp/#post-7358702)
 * 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. 🙂
 *  [David Artiss](https://wordpress.org/support/users/dartiss/)
 * (@dartiss)
 * [10 years ago](https://wordpress.org/support/topic/why-need-compatphp/#post-7358716)
 * 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.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 3 participants
 * Last reply from: [David Artiss](https://wordpress.org/support/users/dartiss/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/why-need-compatphp/#post-7358716)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
