Skip to content

ObjectHelpers::getMagicProperties() missing support for __get and __set properties #330

Closed

Description

@zeleznypa

In my humble opinion, when the entity has the magic __get and/or __set methods and the @property... declaration, the ObjectHelpers::getMagicProperties() should also return them.

/**
 * @property-read string $createdAt
 * @property-read string $id
 */
class PersonEntity
{
    protected array $data = [];

    public function __construct(array $data)
    {
        $uuid = \Ramsey\Uuid\Rfc4122\UuidV7::fromBytes($data['id']);
        $this->data['id'] = $uuid->toString();
        $this->data['createdAt'] = $uuid->getDateTime();
    }

    public function __get(string $name)
    {
        if (isset($this->data[$name]) !== true) {
            throw new InvalidArgumentException();
        }
        return $this->data[$name];
    }
}

$uname = ucfirst($name);
$write = $type !== '-read'
&& $rc->hasMethod($nm = 'set' . $uname)
&& ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
$read = $type !== '-write'
&& ($rc->hasMethod($nm = 'get' . $uname) || $rc->hasMethod($nm = 'is' . $uname))
&& ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
if ($read || $write) {
$props[$name] = $read << 0 | ($nm[0] === 'g') << 1 | $rm->returnsReference() << 2 | $write << 3 | ($type === '-deprecated') << 4;
}

Activity

  1. dg commented on Nov 25, 2025

    @dg
    Member

    This is used purely for the purposes of Nette\SmartObject, which requires the method to be defined.

  2. locked and limited conversation to collaborators on Nov 25, 2025
  3. converted this issue into a discussion #331 on Nov 25, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions