1--TEST--
2Test strncmp() function : error conditions
3--FILE--
4<?php
5/* Prototype  : int strncmp ( string $str1, string $str2, int $len );
6 * Description: Binary safe case-sensitive string comparison of the first n characters
7 * Source code: Zend/zend_builtin_functions.c
8*/
9
10/* Test strncmp() function with more/less number of args and invalid args */
11
12echo "*** Testing strncmp() function: error conditions ***\n";
13$str1 = 'string_val';
14$str2 = 'string_val';
15$len = 10;
16$extra_arg = 10;
17
18var_dump( strncmp() );  //Zero argument
19var_dump( strncmp($str1) );  //One argument, less than expected no. of args
20var_dump( strncmp($str1, $str2) );  //Two arguments, less than expected no. of args
21var_dump( strncmp($str1, $str2, $len, $extra_arg) );  //Four arguments, greater than expected no. of args
22
23/* Invalid argument for $len */
24$len = -10;
25var_dump( strncmp($str1, $str2, $len) );
26echo "*** Done ***\n";
27?>
28--EXPECTF--
29*** Testing strncmp() function: error conditions ***
30
31Warning: strncmp() expects exactly 3 parameters, 0 given in %s on line %d
32NULL
33
34Warning: strncmp() expects exactly 3 parameters, 1 given in %s on line %d
35NULL
36
37Warning: strncmp() expects exactly 3 parameters, 2 given in %s on line %d
38NULL
39
40Warning: strncmp() expects exactly 3 parameters, 4 given in %s on line %d
41NULL
42
43Warning: Length must be greater than or equal to 0 in %s on line %d
44bool(false)
45*** Done ***
46