Created
December 23, 2015 09:04
-
-
Save qoelet/ef26baebcedd55bf96d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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