Skip to content

Instantly share code, notes, and snippets.

@wbond
Created December 2, 2015 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbond/82e6d8cf56ccfaab8894 to your computer and use it in GitHub Desktop.
Save wbond/82e6d8cf56ccfaab8894 to your computer and use it in GitHub Desktop.
How PHP closures have to be created and how I wish they could also be created.
<?php
$conn = fsockopen('localhost', 8080);
$send = function($data) use ($conn) {
fwrite($conn, $data);
}
$send('Hello');
$send('World');
$send('\n');
<?php
$conn = fsockopen('localhost', 8080);
function send($data) use ($conn) {
fwrite($conn, $data);
}
send('Hello');
send('World');
send('\n');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment