Skip to content

add Optional attribute that allows specifying default value #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 6, 2024

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
7 checks passed
@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
2 participants