Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php 8.2 compatibilty issue: Deprecated Functionality #91

Open
CommonSenseSoap opened this issue Jun 7, 2024 · 0 comments
Open

php 8.2 compatibilty issue: Deprecated Functionality #91

CommonSenseSoap opened this issue Jun 7, 2024 · 0 comments

Comments

@CommonSenseSoap
Copy link

I'm receiving an error: Deprecated Functionality: Creation of dynamic property net\authorize\util\Log::$sensitiveStringRegexes is deprecated in ./public_html/vendor/powersync/authorizenet-sdk-php/lib/net/authorize/util/Log.php on line 366

This happened, after switching to PHP 8.2 to prepare Magento 2 updates.

The fix is fairly simple. To fix the error "Creation of dynamic property net\authorize\util\Log::$sensitiveStringRegexes is deprecated", you need to declare the property sensitiveStringRegexes in the Log class explicitly.

Here's the corrected code with the required property declaration added:

<?php
namespace net\authorize\util;

use net\authorize\util\ANetSensitiveFields;

define ("ANET_LOG_FILES_APPEND",true);

define("ANET_LOG_DEBUG_PREFIX","DEBUG");
define("ANET_LOG_INFO_PREFIX","INFO");
define("ANET_LOG_WARN_PREFIX","WARN");
define("ANET_LOG_ERROR_PREFIX","ERROR");

//log levels
define('ANET_LOG_DEBUG',1);
define("ANET_LOG_INFO",2);
define("ANET_LOG_WARN",3);
define("ANET_LOG_ERROR",4);

//set level
define("ANET_LOG_LEVEL",ANET_LOG_DEBUG);

/**
 * A class to implement logging.
 *
 * @package    AuthorizeNet
 * @subpackage net\authorize\util
 */

class Log
{
    private $sensitiveXmlTags = NULL;
    private $logFile = '';
    private $logLevel = ANET_LOG_LEVEL;
    private $sensitiveStringRegexes = [];  // Explicitly declare the property

    /**
     * Takes a regex pattern (string) as argument and adds the forward slash delimiter.
     * Also adds the u flag to enable Unicode mode regex.
     *
     * @param string $regexPattern
     *
     * @return string
     */
    private function addDelimiterFwdSlash($regexPattern)
    {
        return '/'.$regexPattern.'/u';
    }

    /**
     * Takes an xml as string and masks the sensitive fields.
     *
     * @param string $rawString        The xml as a string.
     *
     * @return string        The xml as a string after masking sensitive fields
     */
    private function maskSensitiveXmlString($rawString){
        $patterns=array();
        $replacements=array();

        foreach ($this->sensitiveXmlTags as $i => $sensitiveTag){
            $tag = $sensitiveTag->tagName;
            $inputPattern = "(.+)"; //no need to mask null data
            $inputReplacement = "xxxx";

            if(trim($sensitiveTag->pattern)) {
                $inputPattern = $sensitiveTag->pattern;
            }
            $pattern = "<" . $tag . ">(?:.*)". $inputPattern ."(?:.*)<\/" . $tag . ">";
            $pattern = $this->addDelimiterFwdSlash($pattern);

            if(trim($sensitiveTag->replacement)) {
                $inputReplacement = $sensitiveTag->replacement;
            }
            $replacement = "<" . $tag . ">" . $inputReplacement . "</" . $tag . ">";

            $patterns [$i] = $pattern;
            $replacements[$i]  = $replacement;
        }
        $maskedString = preg_replace($patterns, $replacements, $rawString);
        return $maskedString;
    }

    /**
     * Takes a string and masks credit card regex matching parts.
     *
     * @param string $rawString        The string.
     *
     * @return string        The string after masking credit card regex matching parts.
     */
    private function maskCreditCards($rawString){
        $patterns=array();
        $replacements=array();

        foreach ($this->sensitiveStringRegexes as $i => $creditCardRegex){
            $pattern = $creditCardRegex;
            $pattern = $this->addDelimiterFwdSlash($pattern);

            $replacement = "xxxx";
            $patterns [$i] = $pattern;
            $replacements[$i]  = $replacement;
        }
        $maskedString = preg_replace($patterns, $replacements, $rawString);
        return $maskedString;
    }

    /**
     * Object data masking related functions START
     */

    /**
     * private function getPropertiesInclBase($reflClass).
     *
     * Receives a ReflectionObject, ...
     * iteratively fetches the properties of the object (including from the base classes up the hierarchy), ...
     * collects them in an array of ReflectionProperty and returns the array.
     *
     * @

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant