2007-07-16 10:59:17 +00:00
|
|
|
--TEST--
|
|
|
|
Test substr_count() function (error conditions)
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
|
|
|
|
echo "\n*** Testing error conditions ***\n";
|
2015-07-23 02:01:23 +00:00
|
|
|
$str = 'abcdefghik';
|
|
|
|
|
2007-07-16 10:59:17 +00:00
|
|
|
/* Zero argument */
|
|
|
|
var_dump( substr_count() );
|
|
|
|
|
|
|
|
/* more than expected no. of args */
|
|
|
|
var_dump( substr_count($str, "t", 0, 15, 30) );
|
|
|
|
|
2015-07-23 02:01:23 +00:00
|
|
|
/* offset before start */
|
|
|
|
var_dump(substr_count($str, "t", -20));
|
2007-07-16 10:59:17 +00:00
|
|
|
|
|
|
|
/* offset > size of the string */
|
|
|
|
var_dump(substr_count($str, "t", 25));
|
|
|
|
|
|
|
|
/* Using offset and length to go beyond the size of the string:
|
|
|
|
Warning message expected, as length+offset > length of string */
|
2015-07-23 02:01:23 +00:00
|
|
|
var_dump( substr_count($str, "i", 5, 7) );
|
2007-07-16 10:59:17 +00:00
|
|
|
|
2015-07-23 02:01:23 +00:00
|
|
|
/* Invalid offset argument */
|
|
|
|
var_dump( substr_count($str, "t", "") );
|
|
|
|
|
|
|
|
/* length too small */
|
|
|
|
var_dump( substr_count($str, "t", 2, -20) );
|
|
|
|
|
|
|
|
echo "Done\n";
|
2007-07-16 10:59:17 +00:00
|
|
|
|
|
|
|
?>
|
|
|
|
--EXPECTF--
|
|
|
|
*** Testing error conditions ***
|
|
|
|
|
2008-06-25 12:16:17 +00:00
|
|
|
Warning: substr_count() expects at least 2 parameters, 0 given in %s on line %d
|
2007-07-16 10:59:17 +00:00
|
|
|
NULL
|
|
|
|
|
2008-06-25 12:16:17 +00:00
|
|
|
Warning: substr_count() expects at most 4 parameters, 5 given in %s on line %d
|
2007-07-16 10:59:17 +00:00
|
|
|
NULL
|
|
|
|
|
2015-07-23 02:01:23 +00:00
|
|
|
Warning: substr_count(): Offset not contained in string in %s on line %d
|
2007-07-16 10:59:17 +00:00
|
|
|
bool(false)
|
|
|
|
|
2015-07-23 02:01:23 +00:00
|
|
|
Warning: substr_count(): Offset not contained in string in %s on line %d
|
2007-07-16 10:59:17 +00:00
|
|
|
bool(false)
|
|
|
|
|
2015-07-23 02:01:23 +00:00
|
|
|
Warning: substr_count(): Invalid length value in %s on line %d
|
2007-07-16 10:59:17 +00:00
|
|
|
bool(false)
|
|
|
|
|
2014-12-14 18:20:23 +00:00
|
|
|
Warning: substr_count() expects parameter 3 to be integer, string given in %s on line %d
|
2008-06-25 12:16:17 +00:00
|
|
|
NULL
|
2007-07-16 10:59:17 +00:00
|
|
|
|
2015-07-23 02:01:23 +00:00
|
|
|
Warning: substr_count(): Invalid length value in %s on line %d
|
2007-07-16 10:59:17 +00:00
|
|
|
bool(false)
|
|
|
|
Done
|