1--TEST-- 2Test substr_count() function (error conditions) 3--FILE-- 4<?php 5 6echo "\n*** Testing error conditions ***\n"; 7$str = 'abcdefghik'; 8 9/* offset before start */ 10try { 11 substr_count($str, "t", -20); 12} catch (ValueError $exception) { 13 echo $exception->getMessage() . "\n"; 14} 15 16/* offset > size of the string */ 17try { 18 substr_count($str, "t", 25); 19} catch (ValueError $exception) { 20 echo $exception->getMessage() . "\n"; 21} 22 23/* Using offset and length to go beyond the size of the string: 24 Exception is expected, as length+offset > length of string */ 25try { 26 substr_count($str, "i", 5, 7); 27} catch (ValueError $exception) { 28 echo $exception->getMessage() . "\n"; 29} 30 31/* length too small */ 32try { 33 substr_count($str, "t", 2, -20); 34} catch (ValueError $exception) { 35 echo $exception->getMessage() . "\n"; 36} 37 38echo "Done\n"; 39 40?> 41--EXPECT-- 42*** Testing error conditions *** 43substr_count(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 44substr_count(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 45substr_count(): Argument #4 ($length) must be contained in argument #1 ($haystack) 46substr_count(): Argument #4 ($length) must be contained in argument #1 ($haystack) 47Done 48