There are a couple of ways one would go about assigning a default value to the property, and none seem to work:
Approach 1: The first and naive approach would be to define the value on the sub-property of the object:
public const CCExampleObject = [ self::TYPE => self::TYPE_OBJECT, self::PROPERTIES => [ 'numberOnObject' => [ self::TYPE => self::TYPE_NUMBER, self::REQUIRED => true, self::DEFAULT => 25, ], ], ];
This plain doesn't do anything.
Approach 2: The next approach would be to define the default values on the object as an associative array:
public const CCExampleObject = [ self::TYPE => self::TYPE_OBJECT, self::PROPERTIES => [ 'numberOnObject' => [ self::TYPE => self::TYPE_NUMBER, self::REQUIRED => true, ], ], self::DEFAULT => [ 'numberOnObject' => 25 ], ];
Results in the following error:
DRAFT: Array value found, but an object is required. Key: CCExampleObject
Approach 3: Trying to follow the error message and casting to object:
public const CCExampleObject = [ self::TYPE => self::TYPE_OBJECT, self::PROPERTIES => [ 'numberOnObject' => [ self::TYPE => self::TYPE_NUMBER, self::REQUIRED => true, ], ], self::DEFAULT => (object)[ 'numberOnObject' => 25 ], ];
fails with a PHP error:
Fatal error: Constant expression contains invalid operation
I'm not sure if there is a realistic way to have a class/object inside a class constant.
Maybe our best way forward would be to look into modifying ReflectionSchemaSource to make approach 2 work? Though I'm very much not sure about that.
Please share your thoughts :)