0

I want to something like this:

function __construct (string $todo, array[Tag] $tags) {}

That array[Tag] caused me a problem with error along the line: Unexpected '['

The main idea is to have strict type checking for an array of an object with Tag class.

How can I achieve this? And is it necessary for PHP's best practice?

1

1 Answer 1

0

Short answer, you can't. There is some hacky solution if you really need it though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.