Skip to content

Bug: Entity can't handle column named attributes #5762

Description

@iRedds

CodeIgniter4 Version

4.1.9

What happened?

When using attributes, as the property/attribute name of the Entity class, the Entity::setAttributes() method is called as a setter.
Names collision.

Steps to Reproduce

$e = new CodeIgniter\Entity\Entity();
$e->a = 1;
$e->attributes = [1, 2, 3];  // called the setAttributes method as a setter.
dd($e->toRawArray());

//$e->toRawArray() array (3)
//   0 => integer 1
//   1 => integer 2
//   2 => integer 3

Expected Output

//$e->toRawArray() array (2)
//    a => integer 1
//    attributes => array (3)
//        0 => integer 1
//        1 => integer 2
//        2 => integer 3

Anything else?

In Laravel prior to version 9, the custom setter and getter had the following format:
set/get + AttributeName + Attribute.

public function getFullNameAttribute()
{
    return "{$this->first_name} {$this->last_name}";
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationPull requests for documentation only

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions