yiisoft / yiisoft/hydrator

Try bindTo instead of reflection

Open
#89 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status:under discussion
Dominant language
PHP
Stars
34
Forks
6
Avg merge
17m
Merged PRs (30d)
4

Description

The following could be used to write private / protected properties without reflection. Could be faster.

https://3v4l.org/GqaLf

<?php

final class Guard
{
    private $x = 'test';
}

$guard = new Guard();

$thief = function ($name)
{
    return $this->$name;
};

$hydrator = function ($name, $value) {
    $this->$name = $value;
};


echo $thief->bindTo($guard, Guard::class)('x') . "\n";

$hydrator->bindTo($guard, Guard::class)('x', 'bla');

echo $thief->bindTo($guard, Guard::class)('x') . "\n";

See https://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection/

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named in the issue. Start by locating the hydrator's existing reflection-based property access, then compare its behavior with the bindTo example and linked article. Done would require an agreed replacement scope, equivalent private/protected-property handling, and evidence that the alternative is faster.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.