Skip to content

Using Objects in Properties

Matthew Jordan edited this page Jul 22, 2022 · 2 revisions

Using Objects in Properties

There are two main ways that you can use objects in properties.

The first (and easiest) is to use the MarshalTrait trait on the object's class. Like explained above, both MarshalTrait trait and the Field attribute on the properties are required. Here is an example on how you would use that:

class Range {
	use MarshalTrait;
	
	#[Field]
	public int $min = 0;
	#[Field]
	public int $max = 10;
	#[Field]
	public int $default = 0;
}

class Options {
	use MarshalTrait;
	
	#[Field]
	public string $username = "TestUserName";
	#[Field]
	public Range $range;
}

The second way can be found in the Custom Parsing section.

Clone this wiki locally