recursive/deep array type definition #4738
-
|
Is there a way to express a array-type, in a way that endless level of nesting is allowed, but only from values of type in my use case I want to support a array of payload data and I don't want it to contain any floats. example structure which should report an error $amount = [];
$amount['total'] = $OrderCalculator->getTotalSum(); // returns float, which should be detected as a error
$amount['currency'] = 'EUR';
$amount['details'] = $paymentDetails; // another array
$data['transactions'] = [];
$data['transactions'][]['amount'] = $amount;
myfunc($data);I tried things like nested templates, e.g. but this seem not to work |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
atm I am working with this ugly defintion, which does what I want but only for a fixed number of levels and producing rather ugly error messages - when the types do not match: ugly error |
Beta Was this translation helpful? Give feedback.
-
|
Recursive types aren't supported now and I don't know if they ever will. I recommend using objects instead, you can have property with type |
Beta Was this translation helpful? Give feedback.
Recursive types aren't supported now and I don't know if they ever will. I recommend using objects instead, you can have property with type
selfinside, achieving the same thing and in a safer way.