json-api-php icon indicating copy to clipboard operation
json-api-php copied to clipboard

Document::setData() should be nullable

Open rgazelot opened this issue 8 years ago • 7 comments

I think that the method Document::setData($element) should accept a nullable value as the constructor does.

rgazelot avatar Jun 30 '17 08:06 rgazelot

This will require to change signature to public function setData(?ElementInterface $element) what will lead drop PHP7.0 support. Because nullable types are available since PHP7.1 only.

antonkomarev avatar Sep 27 '17 00:09 antonkomarev

What about public function setData(ElementInterface $element = null)?

rgazelot avatar Sep 27 '17 07:09 rgazelot

By this way you will only be able to do $document->setData(); but not $docuemnt->setData(null). Try it yourself.

antonkomarev avatar Sep 27 '17 10:09 antonkomarev

I agree that PHP7.1 nullable argument are by far the best way to do it, but I'm ok with the PHP7.0 compatibility. Maybe just keep in mind this thing for a future PHP7.1 support?

rgazelot avatar Sep 27 '17 12:09 rgazelot

For PHP 7.0 compatibility, we would probably need a clearData() function then.

franzliedke avatar Sep 28 '17 07:09 franzliedke

What about creating a special case: function setNullData(): void?

f3ath avatar Sep 29 '17 06:09 f3ath

Before implement any of proposed ways we need to define concrete use case for it.

antonkomarev avatar Sep 29 '17 06:09 antonkomarev