1--TEST-- 2socket_set_option() with SO_RCVTIMEO/SO_SNDTIMEO/SO_LINGER 3--EXTENSIONS-- 4sockets 5--FILE-- 6<?php 7$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 8if (!$socket) { 9 die('Unable to create AF_INET socket [socket]'); 10} 11$options_1 = array("sec" => 1, "usec" => "aaaaa"); 12$options_2 = array("sec" => new stdClass(), "usec" => "1"); 13$options_3 = array("l_onoff" => "aaaa", "l_linger" => "1"); 14$options_4 = array("l_onoff" => "1", "l_linger" => []); 15$options_5 = array("l_onoff" => PHP_INT_MAX, "l_linger" => "1"); 16 17try { 18 socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, new stdClass); 19} catch (\ValueError $e) { 20 echo $e->getMessage() . PHP_EOL; 21} 22 23try { 24 socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, $options_1); 25} catch (\TypeError $e) { 26 echo $e->getMessage() . PHP_EOL; 27} 28 29try { 30 socket_set_option( $socket, SOL_SOCKET, SO_SNDTIMEO, $options_2); 31} catch (\TypeError $e) { 32 echo $e->getMessage() . PHP_EOL; 33} 34try { 35 socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, "not good"); 36} catch (\TypeError $e) { 37 echo $e->getMessage() . PHP_EOL; 38} 39try { 40 socket_set_option( $socket, SOL_SOCKET, SO_LINGER, "not good neither"); 41} catch (\TypeError $e) { 42 echo $e->getMessage() . PHP_EOL; 43} 44try { 45 socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_3); 46} catch (\TypeError $e) { 47 echo $e->getMessage() . PHP_EOL; 48} 49try { 50 socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_4); 51} catch (\TypeError $e) { 52 echo $e->getMessage() . PHP_EOL; 53} 54try { 55 socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_5); 56} catch (\ValueError $e) { 57 echo $e->getMessage() . PHP_EOL; 58} 59?> 60--EXPECTF-- 61socket_set_option(): Argument #4 ($value) must have key "sec" 62 63Warning: Object of class stdClass could not be converted to int in %s on line %d 64socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_RCVTIMEO, string given 65socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_LINGER, string given 66socket_set_option(): Argument #4 ($value) "l_onoff" must be between 0 and %d 67