usaepay / usaepay-php

PHP Library for USAePay
http://help.usaepay.com/developer/phplibrary
14 stars 18 forks source link

Php 7 Support? #4

Closed IamSwap closed 7 years ago

IamSwap commented 8 years ago

Getting error while using php 7. preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead. By further digging, problem is this method.

function xmlentities($string)
{
    $string = preg_replace('/[^a-zA-Z0-9 _\-\.\'\r\n]/e', '_uePhpLibPrivateXMLEntities("$0")', $string);
    return $string;
}

But by changing method to following, fixes the problem with php7. But not sure if it's safe.

function xmlentities($string)
{
    $string = preg_replace_callback('[^a-zA-Z0-9 _\-\.\'\r\n]', function($matches) {
        return '_uePhpLibPrivateXMLEntities("$matches[1]")';
    }, $string);
    return $string;
}

Any help?

ajbonner commented 8 years ago

It can be fixed by using preg_replace_callback, and dropping the /e modifier.

 $string = preg_replace_callback('/[^a-zA-Z0-9 _\-\.\'\r\n]/', '_uePhpLibPrivateXMLEntities("$0")', $string);