Skip to content

Casts can't use "ref()" for property name #29

Description

@lachlankrautz

When defining property casts using ref() causes an infinite loop.

/**
 * @property string $my_property_name
 */
class Flim extends DataTransferObject
{
  public static function casts(): array
  {
    return [
      // ref() tries to load the class property data with includes a call to this method to 
      // get the casts and loops infinitely.
      self::ref()->my_property_name => new MyPropertyCast(),
    ];
  }
}

For now just use a string literal.

/**
 * @property string $my_property_name
 */
class Flim extends DataTransferObject
{
  public static function casts(): array
  {
    return [
      // this is safe
      'my_property_name' => new MyPropertyCast(),
    ];
  }
}

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