- fwrite: documentation ( source)
- fopen: documentation ( source)
<?php
$fileHandle = fopen('php://memory', 'r+');
$string = '<?php class Foo { public function __construct($x) { $this->x = $x; } }';
fwrite($fileHandle, '$string');
include 'php://memory';
$test = new Foo(5);