You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add NativePipeRunner and PipePipelineService with multi-step pipeline functionality and tests
* Implement inline @var validation for return statements and add corresponding tests
* Enhance inline `@var` documentation and add support for direct return statement type assertions
Copy file name to clipboardExpand all lines: docs/core-concepts/inline-variables.md
+30-3Lines changed: 30 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Inline Variables (`@var`)
2
2
3
-
While parameter and return contracts protect function boundaries, inline `@var` annotations enforce type safety on local variable assignmentsand reassignments inside function bodies or php file execution lines.
3
+
While parameter and return contracts protect function boundaries, inline `@var` annotations enforce type safety on local variable assignments, reassignments, and direct return statements inside function bodies or PHP scripts.
4
4
5
5
---
6
6
@@ -43,7 +43,7 @@ TypePHP supports both single-variable single-line docblocks and multi-variable d
@@ -79,6 +79,33 @@ Both `/** @var positive-int $count */` and `/** @var positive-int */` behave ide
79
79
80
80
---
81
81
82
+
## Inline `@var` on Direct Return Statements
83
+
84
+
You can place `/** @var Type */` directly above a `return` statement to perform surgical, expression-level type assertion narrowing inside function bodies, closures, or specific conditional branches:
> **PHPStan & Psalm Parity:** Static analysis tools treat `/** @var Type */ return $expr;` as an inline type cast assertion. TypePHP physically enforces this assertion at runtime, ensuring that live dynamic returns strictly satisfy the annotated type.
106
+
107
+
---
108
+
82
109
## Block-Level Scope Isolation & Shadowing
83
110
84
111
TypePHP tracks variable type contracts using **Lexical Block Scope Frames**.
@@ -146,4 +173,4 @@ You can enable or disable specific categories of inline variable validation in `
0 commit comments