tobyzerner / json-api-php

JSON-API (http://jsonapi.org) responses in PHP.
MIT License
436 stars 79 forks source link

Document::setData() should be nullable #130

Open rgazelot opened 7 years ago

rgazelot commented 7 years ago

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

antonkomarev commented 7 years ago

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.

rgazelot commented 7 years ago

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

antonkomarev commented 7 years ago

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

rgazelot commented 7 years ago

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?

franzliedke commented 7 years ago

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

f3ath commented 7 years ago

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

antonkomarev commented 7 years ago

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