Attributes and partial objects
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with AttributesTest.php and the proposed “Uninitialized nested properties” test, then reproduce its failure on unreleased main. Review the implications for partially hydrated objects and ORM usage; done begins with an agreed decision on whether this use case should be supported, followed by a regression test if implementation is chosen.
Written by the indexing model from the issue text.
Description
This issue affects only unreleased main.
Consider this new test for AttributesTest.php:
test('Uninitialized nested properties', function (): void {
$partialAddress = new ReflectionClass(NestedAddress::class)->newInstanceWithoutConstructor();
expect(v::attributes()->isValid(new WithNestedAttributes('John Doe', $partialAddress)))->toBeTrue();
});
Here, I'm using newInstanceWithoutConstructor to create a partial object. This approach has implication for ORMs and other kinds of partial object usage.
This is typical of Doctrine, for example.
Currently, this test fails because Attributes does not skip non-initialized properties.
Before making any change, I would like to open a discussion if we should support this use case or not.
I do have a complete use case for it (involving Respect\Data and partially hydrated entities), in which I don't want to validate if a property was not initialized. If necessary, I can share the example repo.
I believe this also makes a possible BC break, justifying the Attributes work to bump us to 4.x. This repo I'm talking about was fine using Data+Relational (which is also unreleased) but broke with the recent main change on Validation.
- Dominant language
- PHP
- Stars
- 6k
- Forks
- 773
- Avg merge
- 9h 4m
- Merged PRs (30d)
- 19
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.
More from Respect/Validation
-
Feature Gap Support
Respect/Validation#1859 · 1 comment · 1 assignee ·
-
Discussion
Difficulty 5/5 Over a week Newbie friendliness 25/100
Respect/Validation#1800 · 5 comments ·
-
Discussion Enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
Respect/Validation#1789 · 1 comment ·
-
CI/Testing Discussion Enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
Respect/Validation#1710 · 7 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 48/100
Respect/Validation#1681 · 2 comments · 1 reaction ·
All issues in Respect/Validation
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·