|
| 1 | +--TEST-- |
| 2 | +Bug #60110 (fclose(), file_put_contents(), copy() do not return false properly) |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | +class astream |
| 6 | +{ |
| 7 | + public static $max = 100; |
| 8 | + |
| 9 | + public $context; |
| 10 | + |
| 11 | + protected $read = 0; |
| 12 | + |
| 13 | + protected $flush = false; |
| 14 | + |
| 15 | + function stream_open($path, $mode) { |
| 16 | + $this->flush = basename($path) === 'flush'; |
| 17 | + return true; |
| 18 | + } |
| 19 | + |
| 20 | + function stream_write($data) { |
| 21 | + var_dump($data); |
| 22 | + return strlen($data); |
| 23 | + } |
| 24 | + |
| 25 | + function stream_read($length) { |
| 26 | + if ($length > self::$max - $this->read) { |
| 27 | + $length = self::$max - $this->read; |
| 28 | + } |
| 29 | + $this->read += $length; |
| 30 | + return str_repeat('a', $length); |
| 31 | + } |
| 32 | + |
| 33 | + function stream_tell() { |
| 34 | + return $this->read; |
| 35 | + } |
| 36 | + |
| 37 | + function stream_eof() { |
| 38 | + return $this->read == self::$max; |
| 39 | + } |
| 40 | + |
| 41 | + function stream_flush() { |
| 42 | + return $this->flush; |
| 43 | + } |
| 44 | + |
| 45 | + function stream_stat() { |
| 46 | + return fstat(fopen('php://memory', "r")); |
| 47 | + } |
| 48 | + |
| 49 | + function url_stat() { |
| 50 | + return fstat(fopen('php://memory', "r")); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +stream_wrapper_register('as', 'astream'); |
| 55 | + |
| 56 | +$stream = fopen('as://flush', 'r+'); |
| 57 | +var_dump(fwrite($stream, "data")); |
| 58 | +var_dump(fread($stream, 3)); |
| 59 | +var_dump(fclose($stream)); |
| 60 | + |
| 61 | +$stream = fopen('as://nothing', 'r+'); |
| 62 | +var_dump(fwrite($stream, "data")); |
| 63 | +var_dump(fread($stream, 3)); |
| 64 | +var_dump(fclose($stream)); |
| 65 | + |
| 66 | +var_dump(file_put_contents('as://', 'test nothing')); |
| 67 | +var_dump(file_put_contents('as://flush', 'test flush')); |
| 68 | + |
| 69 | +$path = __DIR__ . '/bug60110_test_file.txt'; |
| 70 | +var_dump(file_put_contents($path, 'sdata')); |
| 71 | +var_dump(copy($path, 'as://nothing')); |
| 72 | +var_dump(copy($path, 'as://flush')); |
| 73 | +?> |
| 74 | +--CLEAN-- |
| 75 | +<?php |
| 76 | +@unlink(__DIR__ . '/bug60110_test_file.txt'); |
| 77 | +?> |
| 78 | +--EXPECT-- |
| 79 | +string(4) "data" |
| 80 | +int(4) |
| 81 | +string(3) "aaa" |
| 82 | +bool(true) |
| 83 | +string(4) "data" |
| 84 | +int(4) |
| 85 | +string(3) "aaa" |
| 86 | +bool(false) |
| 87 | +string(12) "test nothing" |
| 88 | +bool(false) |
| 89 | +string(10) "test flush" |
| 90 | +int(10) |
| 91 | +int(5) |
| 92 | +string(5) "sdata" |
| 93 | +bool(false) |
| 94 | +string(5) "sdata" |
| 95 | +bool(true) |
0 commit comments