1--TEST-- 2User-space streams: stream_cast() 3--FILE-- 4<?php 5class test_wrapper_base { 6 public $context; 7 public $return_value; 8 function stream_open($path, $mode, $openedpath) { 9 return true; 10 } 11 function stream_eof() { 12 return false; 13 } 14} 15class test_wrapper extends test_wrapper_base { 16 function stream_cast($castas) { 17 return $this->return_value; 18 } 19} 20function test($name, $fd, $return_value) { 21 echo "\n------ $name: -------\n"; 22 $data = stream_get_meta_data($fd); 23 $data['wrapper_data']->return_value = $return_value; 24 $r = array($fd); 25 $w = $e = null; 26 try { 27 var_dump(stream_select($r, $w, $e, 0) !== false); 28 } catch (TypeError|ValueError $e) { 29 echo $e->getMessage(), "\n"; 30 } 31} 32 33var_dump(stream_wrapper_register('test', 'test_wrapper')); 34var_dump(stream_wrapper_register('test2', 'test_wrapper_base')); 35 36$fd = fopen("test://foo","r"); 37$fd2 = fopen("test2://foo","r"); 38 39test("valid stream", $fd, STDIN); 40test("stream_cast not implemented", $fd2, null); 41test("return value is false", $fd, false); 42test("return value not a stream resource", $fd, "foo"); 43test("return value is stream itself", $fd, $fd); 44test("return value cannot be casted", $fd, $fd2); 45 46?> 47--EXPECTF-- 48bool(true) 49bool(true) 50 51------ valid stream: ------- 52bool(true) 53 54------ stream_cast not implemented: ------- 55 56Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s 57 58Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s 59No stream arrays were passed 60 61------ return value is false: ------- 62 63Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s 64No stream arrays were passed 65 66------ return value not a stream resource: ------- 67 68Warning: stream_select(): test_wrapper::stream_cast must return a stream resource in %s 69 70Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s 71No stream arrays were passed 72 73------ return value is stream itself: ------- 74 75Warning: stream_select(): test_wrapper::stream_cast must not return itself in %s 76 77Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s 78No stream arrays were passed 79 80------ return value cannot be casted: ------- 81 82Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s 83 84Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s 85 86Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s 87No stream arrays were passed 88