Skip to content

Commit 37ff05d

Browse files
committed
docs: #139 fluent and nested method calls
1 parent a2f955b commit 37ff05d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

content/documentation/php-interop.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,24 @@ Evaluates `expr` and creates a new PHP class using the arguments. The instance o
5555

5656
Calls a method or property on a PHP object. Both `methodname` and `property` must be symbols and cannot be an evaluated value.
5757

58+
You can chain multiple method calls or property accesses in one `php/->` expression. Each element is evaluated sequentially on the result of the previous call, allowing fluent-style interactions or access to nested properties.
59+
5860
```phel
5961
(ns my\module)
6062
6163
(def di (php/new \DateInterval "PT30S"))
6264
6365
(php/-> di (format "%s seconds")) # Evaluates to "30 seconds"
6466
(php/-> di s) # Evaluates to 30
67+
68+
# Chain multiple calls:
69+
# (new DateTimeImmutable("2024-03-10"))->modify("+1 day")->format("Y-m-d")
70+
(php/-> (php/new \DateTimeImmutable "2024-03-10")
71+
(modify "+1 day")
72+
(format "Y-m-d"))
73+
74+
# Mix methods and properties: $user->profile->getDisplayName()
75+
(php/-> user profile (getDisplayName))
6576
```
6677

6778
## PHP static method and property call

0 commit comments

Comments
 (0)