- Affected version
- XF2.3 Beta 4
These collection classes result in entity property type hints of;
This has edge cases where the exact return type doesn't really match and iterating can lose the proper type hint. Especially if calling methods on
It would be nice if this was;
Thankfully via phpdocs we can do this:
This then requires patching the references to
PHP:
/**
* @property-read \MyAddon\Entity\Foo[]|\XF\Mvc\Entity\AbstractCollection
*/
AbstractCollection
It would be nice if this was;
PHP:
/**
* @property-read \XF\Mvc\Entity\AbstractCollection<\MyAddon\Entity\Foo>
*/
Thankfully via phpdocs we can do this:
PHP:
/**
* @template T of \XF\Mvc\Entity\Entity
* @template-extends \ArrayObject<string|int,T>
* @template-implements \IteratorAggregate<T>
* @template-implements \ArrayAccess<string|int,T>
*/
abstract class AbstractCollection implements \Countable, \IteratorAggregate, \ArrayAccess
This then requires patching the references to
Entity
to T
, including some non-hinted return types to ensure everything accurately preserves type hinting. This includes when ArrayCollection
or AbstractCollection
is returned.
Last edited: