1--TEST-- 2setcookie() error tests 3--INI-- 4date.timezone=UTC 5--FILE-- 6<?php 7 8ob_start(); 9 10try { 11 setcookie(''); 12} catch (\ValueError $e) { 13 echo $e->getMessage() . "\n"; 14} 15try { 16 setcookie('invalid='); 17} catch (\ValueError $e) { 18 echo $e->getMessage() . "\n"; 19} 20try { 21 setcookie('name', 'invalid;'); 22} catch (\ValueError $e) { 23 echo $e->getMessage() . "\n"; 24} 25try { 26 setcookie('name', 'value', 100, 'invalid;'); 27} catch (\ValueError $e) { 28 echo $e->getMessage() . "\n"; 29} 30try { 31 setcookie('name', 'value', 100, 'path', 'invalid;'); 32} catch (\ValueError $e) { 33 echo $e->getMessage() . "\n"; 34} 35 36if (PHP_INT_SIZE == 8) { 37 try { 38 // To go above year 9999: 60 * 60 * 24 * 365 * 9999 39 setcookie('name', 'value', 315328464000); 40 } catch (\ValueError $e) { 41 var_dump($e->getMessage() == 'setcookie(): "expires" option cannot have a year greater than 9999'); 42 } 43} else { 44 var_dump(true); 45} 46 47var_dump(headers_list()); 48 49?> 50--EXPECTHEADERS-- 51 52--EXPECTF-- 53setcookie(): Argument #1 ($name) must not be empty 54setcookie(): Argument #1 ($name) cannot contain "=", ",", ";", " ", "\t", "\r", "\n", "\013", or "\014" 55setcookie(): "path" option cannot contain ",", ";", " ", "\t", "\r", "\n", "\013", or "\014" 56setcookie(): "domain" option cannot contain ",", ";", " ", "\t", "\r", "\n", "\013", or "\014" 57bool(true) 58array(2) { 59 [0]=> 60 string(%d) "X-Powered-By: PHP/%s" 61 [1]=> 62 string(27) "Set-Cookie: name=invalid%3B" 63} 64