Try bindTo instead of reflection
Open
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.
<?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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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