Skip to content

Add experimental list<T> type declarations#21941

Closed
tony1877 wants to merge 1 commit intophp:masterfrom
tony1877:better-list-types-squashed
Closed

Add experimental list<T> type declarations#21941
tony1877 wants to merge 1 commit intophp:masterfrom
tony1877:better-list-types-squashed

Conversation

@tony1877
Copy link
Copy Markdown

@tony1877 tony1877 commented May 3, 2026

This adds an experimental list type declaration prototype.

Implemented:

  • parser support for list
  • runtime validation for parameters, return types, and properties
  • list-shape validation using zend_array_is_list()
  • element type validation
  • nullable ?list
  • Reflection string rendering as list
  • return covariance with array
  • parameter contravariance with array
  • explicit rejection of list inside union types for now

Tests run:

  • sapi/cli/php run-tests.php Zend/tests/type_declarations/list_type_*.phpt
    • 14 passed, 0 failed
  • sapi/cli/php run-tests.php Zend/tests/type_declarations
    • 503 passed, 7 skipped, 0 failed
  • sapi/cli/php run-tests.php ext/reflection
    • 505 passed, 13 skipped, 0 failed
  • sapi/cli/php run-tests.php Zend/tests/type_declarations/typed_properties_*.phpt
    • 119 passed, 1 skipped, 0 failed
  • sapi/cli/php run-tests.php Zend/tests/type_declarations/variance Zend/tests/type_declarations/union_types/variance Zend/tests/type_declarations/intersection_types/variance
    • 78 passed, 0 failed

Notes:

  • This is a prototype and intentionally keeps union support out of scope because the existing union type machinery assumes complex list payloads are union/intersection/class-name shaped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants