除了PHP数组之外,处理PHP对象集合的好结构是什么?

I have a need to manage, handle, and manipulate a [set, collection] of objects.

I am thinking of creating a class that manages set of these objects.

What data structure can I use for this?

Example use:

$setManager = new SetManager();
$setManager->getCase($caseNum);
$ave = $setManager->getAverageValueForPropertyXFromAllCases();

$case = new Case();
$setManager->setCase($pos, $case);

I can use anything I want inside SetManager, I have been using arrays, but my IDE has various issues with using autocomplete on arrays, and I am seeking other structures.

  • What IDE are you using, it may be a known issue with a resolution?
  • What issues with autocomplete are you having?

Most IDE's support annotations or have addons to add support for annotations and autocomplete.

For example

/** @var MyObject[]|array $myVar */
$myVar = [];

For an actual demonstration of annotation autocomplete on an array of objects.

enter image description here

You can even specify multiple types of objects that can be in the array and be accepted by a setter method.