Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created December 23, 2015 09:04
Show Gist options
  • Save qoelet/ef26baebcedd55bf96d9 to your computer and use it in GitHub Desktop.
Save qoelet/ef26baebcedd55bf96d9 to your computer and use it in GitHub Desktop.
<?php
class WithFileContents {
private $resource = null;
private function open($f) {
$this->resource = fopen($f, "r");
}
public function run($resource, $fun) {
if(is_callable($fun)) {
$this->open($resource);
$contents = fread($this->resource, filesize($resource));
$fun($contents);
$this->close();
}
}
private function close() {
fclose($this->resource);
}
}
$f = function ($c) {
printf("%s", $c);
};
$with = new WithFileContents ();
$with->run("withPattern.php", $f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment