Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

zeleznypa started this conversation in General
Discussion options

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;
}
You must be logged in to vote

Replies: 1 comment

Comment options

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

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #330 on November 25, 2025 12:29.

AltStyle によって変換されたページ (->オリジナル) /