- file_get_contents: documentation ( source)
- fclose: documentation ( source)
- fwrite: documentation ( source)
- fopen: documentation ( source)
<?php
final class Example
{
private $variable;
public function __construct($variable)
{
$this->variable = fopen('php://memory', 'rw+');
fwrite($this->variable, $variable);
}
public function example()
{
return file_get_contents($this->variable);
}
public function setExample($variable)
{
fwrite($this->variable, $variable);
}
public function __destruct()
{
fclose($this->variable);
}
}
$example = new Example('first');
print $example->example() . PHP_EOL;
$example->setExample('second');
print $example->example() . PHP_EOL;