Skip to content

Commit 8c5e9a3

Browse files
committed
Update demo with closure vars
1 parent 319d60b commit 8c5e9a3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

demos/demo.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
echo date('c') . ' :: Sending process. You should not wait any longer to see next message: ' . PHP_EOL;
1111

1212
try {
13-
$process->send(function () {
13+
$age = 30;
14+
$name = 'John Doe';
15+
$fruits = ['orange', 'apple', 'grape'];
16+
$process->send(function () use ($age, $name, $fruits) {
1417
sleep(5);
15-
echo 123;
16-
file_put_contents('demo.txt', 'Hello, World! At: ' . date('c'));
18+
echo 123; // you should not see this anywhere
19+
file_put_contents(
20+
'demo.txt',
21+
"Age: $age\nName: $name\nFruits: " . implode(', ', $fruits) . ' - ' . date('c')
22+
);
1723
});
1824
} catch (Exception $e) {
1925
echo $e->getMessage();

0 commit comments

Comments
 (0)