Respect / Respect/Validation

Attributes and partial objects

Open
#1,803 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
6k
Forks
773
Avg merge
10h 6m
Merged PRs (30d)
17

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.

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

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.