Skip to content

Entities without nullable non-null properties #29631

Open
@ChristophWurst

Description

How to use GitHub

  • Please use the 👍 reaction to show that you are interested into the same feature.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Is your feature request related to a problem? Please describe.

Entities for db table abstraction represent one row of a database table. However, they do not reflect that some properties are never null. You can create an instance of an entity class without specifying any value. Not even the primary key is enforced.

$account = new Account();
$account->getId(); // NULL

Describe the solution you'd like

Allow entities to have a constructor with arguments that map directly to object properties.

class Account extends Entity {

	/** @var string */
	protected $userId;

	public function __construct(int $id, string $userId) {
		$this->id = $id;
		$this->userId = $userId;
	}
}

$account = new Account(123, 'admin');
$account->getId(); // Impossible to get NULL here

Describe alternatives you've considered

n/a

Additional context

n/a


@miaulalala as discussed

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions