Преглед изворни кода

Merge pull request #184 from kander/patch-2

Fixing #157 - preg_replace() with /e modifier under PHP 5.5 is deprecate...
Matthew Weier O'Phinney пре 12 година
родитељ
комит
8152faed0b
1 измењених фајлова са 14 додато и 2 уклоњено
  1. 14 2
      library/Zend/Ldap/Converter.php

+ 14 - 2
library/Zend/Ldap/Converter.php

@@ -69,11 +69,23 @@ class Zend_Ldap_Converter
      */
      */
     public static function hex32ToAsc($string)
     public static function hex32ToAsc($string)
     {
     {
-        $string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);
+        // Using a callback, since PHP 5.5 has deprecated the /e modifier in preg_replace.
+        $string = preg_replace_callback("/\\\([0-9A-Fa-f]{2})/", array('Zend_Ldap_Converter', '_charHex32ToAsc'), $string);
         return $string;
         return $string;
     }
     }
 
 
     /**
     /**
+     * Convert a single slash-prefixed character from Hex32 to ASCII.
+     * Used as a callback in @see hex32ToAsc()
+     * @param array $matches
+     *
+     * @return string
+     */
+    private static function _charHex32ToAsc(array $matches) {
+        return chr(hexdec($matches[0]));
+    }
+
+    /**
      * Convert any value to an LDAP-compatible value.
      * Convert any value to an LDAP-compatible value.
      *
      *
      * By setting the <var>$type</var>-parameter the conversion of a certain
      * By setting the <var>$type</var>-parameter the conversion of a certain
@@ -394,4 +406,4 @@ class Zend_Ldap_Converter
         }
         }
         return $v;
         return $v;
     }
     }
-}
+}