Skip to content

ResourceFactory.php - Deprecated functionality #249

Description

@homerjsim

I get this error:
2025-07-27T07:43:13+00:00 ERR (3): Deprecated functionality: Creation of dynamic property Mollie\Api\Resources\Method::$resource is deprecated in /lib/Mollie/Mollie/src/Resources/ResourceFactory.php on line 18

and I fixed it with this code. So maybe someone can implement it in a new release.

<?php

namespace Mollie\Api\Resources;

class ResourceFactory
{
    /**
     * Create resource object from Api result
     *
     * @param object $apiResult
     * @param BaseResource $resource
     *
     * @return BaseResource
     */
    public static function createFromApiResult($apiResult, BaseResource $resource)
    {
        foreach ($apiResult as $property => $value) {
            // Check if property exists or if class allows dynamic properties
            if (property_exists($resource, $property) || method_exists($resource, '__set')) {
                $resource->{$property} = $value;
            } else {
                // For classes that don't allow dynamic properties, 
                // you might want to store in a data array or skip unknown properties
                if (method_exists($resource, 'setData')) {
                    $resource->setData($property, $value);
                } elseif (property_exists($resource, 'data') || method_exists($resource, '__get')) {
                    // Fallback: still set the property but suppress the warning
                    @$resource->{$property} = $value;
                }
            }
        }

        return $resource;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions