Skip to content

RawData trait uses 'mixed' type hints incompatible with PHP 7.4 #279

@daniolivet8

Description

@daniolivet8

Description

The RawData trait in both v1 and v2 uses mixed type hints (property declaration, parameter, and return type), which were introduced in PHP 8.0. This causes a fatal error on PHP 7.4 despite composer.json declaring "php": "^7.4 || ^8.0".

Affected files

  • lib/versions/v1/Traits/RawData.php
  • lib/versions/v2/Traits/RawData.php

Error

Argument 1 passed to Pipedrive\versions\v2\Model\DealItem::setRawData() must be an instance of Pipedrive\versions\v2\Traits\mixed, instance of stdClass given, called in vendor/pipedrive/pipedrive/lib/versions/v2/ObjectSerializer.php on line 405

PHP 7.4 interprets mixed as a class name within the current namespace instead of the native type.

Current code (v2 example)

trait RawData
{
    private mixed $rawData;

    public function getRawData(): mixed
    {
        return $this->rawData;
    }

    public function setRawData(mixed $rawData): void
    {
        $this->rawData = is_object($rawData) && property_exists($rawData, 'data') ? $rawData->data : $rawData;
    }
}

Suggested fix

Remove mixed type hints to maintain PHP 7.4 compatibility (the @var, @param, and @return PHPDoc annotations already document the types):

trait RawData
{
    /** @var mixed */
    private $rawData;

    /** @return mixed */
    public function getRawData()
    {
        return $this->rawData;
    }

    /** @param mixed $rawData */
    public function setRawData($rawData): void
    {
        $this->rawData = is_object($rawData) && property_exists($rawData, 'data') ? $rawData->data : $rawData;
    }
}

Environment

  • SDK version: 15.4.0
  • PHP version: 7.4.33

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions