Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As of php 5.5 I am getting the message:
Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ldap_pear_hex2asc()
Attached is my attempt to fix, but I am not entirely certain of the syntax, namely the double single-quote usage.
Comments
Comment #1
jay.dansand CreditAttribution: jay.dansand commentedI was just coming to create an issue of my own, but hooray there's already one here! Taking a quick look at HEAD of 7.x-2.x, this issue is already fixed:
So I'm changing this issue to 7.x-1.x-dev (thousands of folks are still on the 7.x-1.x branch, and the project page says "It is recommended to stick with whatever version of it you have working currently until 7.x-2.0RCs come out," so there will probably continue to be many users of the 7.x-1.x branch even on PHP 5.5.
Anonymous functions break PHP support prior to PHP 5.3.0 (see PHP manual entry for Anonymous Functions), and Drupal 7 supports PHP 5.2.5+ (see Drupal's System requirements). That means, to keep an anonymous-ish solution while staying within Drupal's supported systems, we need to fall back on
create_function()
. I'm attaching a patch against 7.x-1.x-dev that usescreate_function()
(we're using this in production).Comment #2
kenorb CreditAttribution: kenorb commentedComment #3
johnbarclay CreditAttribution: johnbarclay commentedThis still throws an error for me on 7.x-2.0-dev. The following works and is more readable (to me)
Comment #4
jay.dansand CreditAttribution: jay.dansand commentedIn the latest LDAP 7.x-2.x-dev, the "/e modifier is deprecated" notice should never happen, because either:
preg_replace_callback()
are used (no/e
modifier), or/e
modifier is not deprecated yet (/e is deprecated in PHP 5.5.x)So if you're experiencing the problem, I suggest either using the latest 7.x-2.x-dev (I just double-checked the code and it should still be good - but if you're on the latest version and still getting this notice, and you're sure your Zend Opcache has been cleared and that it isn't running into a cache collision with someone else's older LDAP installation running on the same machine, then let's get to the bottom of it!), or copying that bit of the code out of 7.x-2.x-dev and applying it to whatever version you are using.
At the very least, I'd definitely recommend changing your patch, because every time
create_function()
is invoked, even if it's to create the same exact function, it runseval()
and creates an additional copy of thelambda_N
function in the global space. This starts gobbling up memory and also slows down PHP (see the manual page for create_funciton()), so it's a best practice to cache the output ofcreate_function()
in a static variable and then reuse that:But really, in PHP 5.3.0+, it's recommended to use proper anonymous functions, as 7.x-2.x-dev does. Quote from php.net's create_function() manual entry:
Comment #5
jay.dansand CreditAttribution: jay.dansand commentedHere's a straight port of the 7.x-2.x branch's
ldap_pear_hex2asc()
function in a patch rolled against latest 7.x-1.x.Comment #7
grahlI've backported the current 2.x version which is still different. < 5.3 is dropped.