Skip to content

Conversation

@JanTvrdik
Copy link
Member

Resolves #59.

Add alternative approach to dealing with undefined values, that does not require wrapping values with generic Optional. This makes it impossible to distinguish between undefined and default value (usually null), but is overall simpler to deal with.

readonly class Semaphore
{
    public function __construct(
        #[Optional(default: SemaphoreColorEnum::Red)]
        public SemaphoreColorEnum $color,

        #[Optional]
        public ?string $manufacturer,
    ) {
    }
}

@JanTvrdik JanTvrdik mentioned this pull request May 31, 2024
@JanTvrdik JanTvrdik requested review from janedbal and olsavmic May 31, 2024 14:21
@janedbal
Copy link
Member

janedbal commented Jun 5, 2024

Readme change missing

@JanTvrdik JanTvrdik merged commit cc5fb15 into master Jun 6, 2024
@JanTvrdik JanTvrdik deleted the optional-attribute branch June 6, 2024 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional optional

3 participants