Showing results for 
Search instead for 
Did you mean: 

Return type should be compatible with JsonSerializable::jsonSerialize()

After connecting successfully to the with this line of code:

$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); 

I receive this error in my browser: 

An error occurred in script 'C:\xampp\htdocs\vendor\lib\net\authorize\api\contract\v1\MerchantAuthenticationType.php' on line 260: Return type of net\authorize\api\contract\v1\MerchantAuthenticationType::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

I tried to supress the error in MerchantAuthenticationType.php, by placing #[\ReturnTypeWillChange] over the jsonSerialize() function as the error suggests:

// Json Serialize Code
public function jsonSerialize(){
$values = array_filter((array)get_object_vars($this),
function ($val){
return !is_null($val);
$mapper = \net\authorize\util\Mapper::Instance();
foreach($values as $key => $value){
$classDetails = $mapper->getClass(get_class() , $key);
if (isset($value)){
if ($classDetails->className === 'Date'){
$dateTime = $value->format('Y-m-d');
$values[$key] = $dateTime;
else if ($classDetails->className === 'DateTime'){
$dateTime = $value->format('Y-m-d\TH:i:s\Z');
$values[$key] = $dateTime;
if (is_array($value)){
if (!$classDetails->isInlineArray){
$subKey = $classDetails->arrayEntryname;
$subArray = [$subKey => $value];
$values[$key] = $subArray;
return $values;

This suppressed the error but then I received the following error:

An error occurred in script 'C:\xampp\htdocs\vendor\lib\net\authorize\util\Log.php' on line 162:
preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

This is the line of code that the new error is referring to in Log.php on line 162:


The full method from Log.php is which contains this line of code is:

private function checkPropertyAndMask($prop, $obj){
foreach($this->sensitiveXmlTags as $i => $sensitiveField)
$inputPattern = "(.+)";
$inputReplacement = "xxxx";

if(trim($sensitiveField->pattern)) {
$inputPattern = $sensitiveField->pattern;
$inputPattern = $this->addDelimiterFwdSlash($inputPattern);

if(trim($sensitiveField->replacement)) {
$inputReplacement = $sensitiveField->replacement;

return $prop->getValue($obj);
return false;

Any help from someone familiar with this error would greatly be appreciated.




public JsonSerializable::jsonSerialize(): mixed



Serializes the object to a value that can be serialized natively by json_encode().