EN49

Page 418

}

Section 89.4: Collections PSR-5 proposes a form of Generics-style notation for collections. Generics Syntax Type[] Type<Type> Type<Type[, Type]...> Type<Type[|Type]...>

Values in a Collection MAY even be another array and even another Collection. Type<Type<Type>> Type<Type<Type[, Type]...>> Type<Type<Type[|Type]...>>

Examples <?php /** * @var ArrayObject<string> $name */ $name = new ArrayObject(['a', 'b']); /** * @var ArrayObject<int> $name */ $name = new ArrayObject([1, 2]); /** * @var */ $name = new new ]);

ArrayObject<stdClass> $name new ArrayObject([ stdClass(), stdClass()

/** * @var ArrayObject<string|int|stdClass|bool> $name */ $name = new ArrayObject([ 'a', true, 1, 'b', new stdClass(), 'c', 2 ]); /** * @var */ $name = new new ]);

ArrayObject<ArrayObject<int>> $name new ArrayObject([ ArrayObject([1, 2]), ArrayObject([1, 2])

GoalKicker.com – PHP Notes for Professionals

405


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.