When doing a ldap sync, i get this "warning":

ldap_servers: Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead i ldap_pear_hex2asc() (linje 381 af ...sites/all/modules/ldap/ldap_servers/ldap_servers.functions.inc).

This code should remove the warning:

function ldap_pear_hex2asc($string) {
$string = preg_replace_callback(
"/\\\([0-9A-Fa-f]{2})/",
function ($m){
return chr(hexdec($m[1]));
},
$string);

return $string;
}

Comments

johnbarclay’s picture

Version: 7.x-2.0-beta6 » 7.x-2.x-dev
Status: Active » Needs review

this is committed.

dbfunk’s picture

that code crashes on a site built on a PHP-5.2 server.

johnbarclay’s picture

this is fixed in 7.x-2.x-dev. Here's the new code:

      if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
        $string = preg_replace_callback(
          "/\\\([0-9A-Fa-f]{2})/",
          function ($m){
            return chr(hexdec($m[1]));
          },
          $string);
      }
      else {
        $string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);
      }

johnbarclay’s picture

Status: Needs review » Closed (fixed)
nimbfire@gmail.com’s picture

The proposal of #3 didn't work for me. The drush still says:

Drush command terminated abnormally due to an unrecoverable error.   [error]
Error: syntax error, unexpected T_FUNCTION in
/path/to/website/sites/all/modules/ldap/ldap_servers/ldap_servers.functions.inc,
line 386

Only when I commented this function it was able to install it =(.

PHP: 5.2.17

katannshaw’s picture

@nimbfire: I'm using PHP 5.5.23 and this code from 7.x-2.x-dev (@ ldap/ldap_servers/ldap_servers.functions.inc) worked for me when I replaced this code on Line 380:

* @return string
    */
    function ldap_pear_hex2asc($string) {
        $string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);
        return $string;
    }

with this:

* @return string
    */
    
    function ldap_pear_hex2asc($string) {

      if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
        $string = preg_replace_callback(
          "/\\\([0-9A-Fa-f]{2})/",
          function ($m){
            return chr(hexdec($m[1]));
          },
          $string);
      }
      else {
        $string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);
      }

      return $string;
    }
genat’s picture

Thanks jayhawkfan75! Worked for us too!

katannshaw’s picture

@itbgt: That's great to hear! I'm glad that it was helpful.