0

What is the proper syntax to declare a type string[] attribute in php?

protected string[] $array_of_strings;

does gives an error at '['

4
  • 2
    PHP doesn’t have such syntax. You can use @return string[] in a docblock if you need an IDE to pick it up Commented Mar 10, 2022 at 19:05
  • 2
    @Clive In this case, it's a property, not a function return type, so it would be @var string[] Commented Mar 10, 2022 at 19:36
  • Side note: this is a "property"; in PHP 8, there is a completely separate thing called an "attribute", so you may confuse people if you use the wrong term. Commented Mar 10, 2022 at 19:44
  • 1
    Bruh I was finishing my answer when this got closed! you can only do protected array $array_of_strings; php.net/manual/en/… php.net/manual/en/… Commented Mar 10, 2022 at 19:44

1 Answer 1

-2

You can also use like:

$Array = ["foo","bar", "value"];

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.