internal/stubs/TEMPLATE_ANNOTATIONS.md
This document tracks all hand-crafted template annotations in .phan/internal_stubs/ that MUST be preserved during stub regeneration.
Generated: 2025-10-27
Location: Lines 741-758
/**
* @template TObject of object
* @template TValue
* @implements Iterator<int, TObject>
* @implements ArrayAccess<TObject, TValue>
*/
class SplObjectStorage implements \Countable, \SeekableIterator, \Serializable, \ArrayAccess {
/**
* @suppress PhanGenericConstructorTypes
*/
public function __construct() {}
Method-level annotations:
attach(object $object, mixed $info): @param TObject $object, @param TValue $infodetach(object $object): @param TObject $objectcontains(object $object): @param TObject $objectaddAll(\SplObjectStorage $storage): @param SplObjectStorage<TObject, TValue> $storageremoveAll(\SplObjectStorage $storage): @param SplObjectStorage<TObject, TValue> $storageremoveAllExcept(\SplObjectStorage $storage): @param SplObjectStorage<TObject, TValue> $storagegetInfo(): @return TValuesetInfo(mixed $info): @param TValue $infocurrent(): @return TObjectoffsetExists($object): @param TObject $objectoffsetGet($object): @param TObject $object, @return TValueoffsetSet($object, mixed $info): @param TObject $object, @param TValue $infooffsetUnset($object): @param TObject $objectLocation: Lines 927-957 Note: WeakMap is actually from Core extension but kept in SPL stub for templating convenience
/**
* @template TKey of object
* @template TValue
* @implements ArrayAccess<TKey, TValue>
* @implements IteratorAggregate<TKey, TValue>
*/
class WeakMap implements \ArrayAccess, \IteratorAggregate, \Countable {
Method-level annotations:
offsetGet(object $object): @param TKey $object, @return TValueoffsetSet(object $object, mixed $value): @param TKey $object, @param TValue $valueoffsetExists(object $object): @param TKey $objectoffsetUnset(object $object): @param TKey $objectgetIterator(): @return \Iterator<TKey, TValue>Location: Lines 784-849
Note: Same template annotations as spl.phan_php but implements \Iterator instead of \SeekableIterator (seek() method added in PHP 8.4)
/**
* @template TObject of object
* @template TValue
* @implements Iterator<int, TObject>
* @implements ArrayAccess<TObject, TValue>
*/
class SplObjectStorage implements \Countable, \Traversable, \Iterator, \Serializable, \ArrayAccess {
All method-level annotations same as spl.phan_php above.
Location: Lines 966-996 Note: Identical to spl.phan_php version
Purpose: Provides template annotations for standard library functions that preserve types through transformations.
/**
* @template TKey
* @template TValue
* @param array<TKey, TValue> $array
* @param callable(TValue, TKey): bool $callback
* @return TValue|null
*/
function array_find(array $array, callable $callback) {}
/**
* @template TKey
* @template TValue
* @param array<TKey, TValue> $array
* @param callable(TValue, TKey): bool $callback
* @return TKey|null
*/
function array_find_key(array $array, callable $callback) {}
/**
* @template TKey
* @template TValue
* @param array<TKey, TValue> $array
* @param callable(TValue, TKey): bool $callback
*/
function array_any(array $array, callable $callback): bool {}
/**
* @template TKey
* @template TValue
* @param array<TKey, TValue> $array
* @param callable(TValue, TKey): bool $callback
*/
function array_all(array $array, callable $callback): bool {}
| File | PHP 8.1 | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|---|
| spl.phan_php | ✗ | ✗ | ✗ | ✓ | ✓ |
| spl_php81.phan_php | ✓ | ✓ | ✓ | ✗ | ✗ |
| standard_templates.phan_php | ✓ | ✓ | ✓ | ✓ | ✓ |
Key difference: PHP 8.4+ supports typed constants and SplObjectStorage::seek() method