Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: preg_match(): Compilation failed at wp-db.php on line 1657

Discussion in 'Misc WordPress Requests' started by crkm, Nov 21, 2017.

  1. crkm


    Reply To: preg_match(): Compilation failed at wp-db.php on line 1657, by crkm

    Pioneer Web Design: Welcome back, though I don’t follow what you are saying.

    Anyway, while doing some digging into the specific problem raised by the OP, I came across this:
    Example #4 on http://php.net/manual/en/function.preg-match.php
    Apologies for the no doubt incorrect formatting


    $str = 'foobar: 2008';

    preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);

    /* This also works in PHP 5.2.2 (PCRE 7.0) and later, however
    * the above form is recommended for backwards compatibility */
    // preg_match('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);



    The wp-db.php file from WP 4.9 uses the syntax ?< rather than ?P< in lines relevant to line 1657.
    See below, my highlighting, snippet ends at line 1657.

    * @since 4.9.0
    * @param string $host The DB_HOST setting to parse.
    * @return array|bool Array containing the host, the port, the socket and whether
    * it is an IPv6 address, in that order. If $host couldn't be parsed,
    * returns false.
    public function parse_db_host( $host ) {
    $port = null;
    $socket = null;
    $is_ipv6 = false;

    // We need to check for an IPv6 address first.
    // An IPv6 address will always contain at least two colons.
    if ( substr_count( $host, ':' ) > 1 ) {
    <strong>$pattern = '#^(?:\[)?(?<host>[0-9a-fA-F:]+)(?:\]:(?<port></strong>[\d]+))?(?:/(?<socket>.+))?#';
    $is_ipv6 = true;
    } else {
    // We seem to be dealing with an IPv4 address.
    <strong>$pattern = '#^(?<host>[^:/]*)(?::(?<port>[\d]+))?(?::(?<socket>.+))?#';</strong>

    $matches = array();
    $result = preg_match( $pattern, $host, $matches );

    Adding the P i,e changing ?< to ?P< in the highlighted lines in the WP 4.9 version of wp-db.php and reloading manually WP 4.9 (with modified wp-db.php) on my site (curtc.net hosted by Easily) causes the Warning highlighted by the OP to go away… As far as I can tell the site is fully functional.

    Of course this is not conclusive as Easily could have updated their php version by now.

    Please note, I’m no php expert but this has worked for me. But please proceed at your own risk and frankly I don’t recommend it.

    Again, thanks to those who have helped with the problem highlighted by the OP.

    Edit Highlighting in the 2nd code box appears as the code for bold and end code for bold, i.e. the lines containing $pattern

    Reply To: preg_match(): Compilation failed at wp-db.php on line 1657

Share This Page

Monarch Social Sharing Plugin