Skip to content

Limitations

Matthew Jordan edited this page Apr 23, 2022 · 1 revision

Limitations

As the library stands, the constructor is never called when creating an object. This is intentional as argument ordering may have unintended side effects. If you want to be able to pass in parameters to an object, you can take advantage of PHP's promoted properties like so:

class User {
	use MarshalTrait;

	public function __construct(
		#[Field(name: "first-name")]
		public string $firstName,
		#[Field(name: "last-name")]
		public string $lastName,
		#[Field]
		public int $age,
		#[Field]
		public string $email
	) {}
}

This will allow you to create the objects through a constructor as usual while also declaring the properties.

Clone this wiki locally