- file_get_contents: documentation ( source)
- stream_wrapper_register: documentation ( source)
- stream_wrapper_unregister: documentation ( source)
<?php
stream_wrapper_unregister('file');
stream_wrapper_register('file', InvalidStreamWrapper::class);
echo '========file_get_contents' . PHP_EOL;
echo file_get_contents('non-exists-file');
echo '========require' . PHP_EOL;
require 'non-exists-file';
class InvalidStreamWrapper
{
public $context;
private $content = "<?php echo time() . PHP_EOL; ?>\n";
private $size = 32;
private $counter = 0;
public function stream_read($count)
{
if ($this->counter > 2) {
return '';
}
$this->counter++;
return $this->content;;
}
public function stream_stat()
{
return ['size' => $this->size];
}
public function stream_open($path, $mode, $options, &$opened_path): bool
{
return true;
}
public function stream_eof(): bool
{
return true;
}
public function stream_set_option($option, $arg1, $arg2)
{
return true;
}
}