1--TEST--
2Test strtok() function : error conditions
3--FILE--
4<?php
5/* Prototype  : string strtok ( string $str, string $token )
6 * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
7 * Source code: ext/standard/string.c
8*/
9
10/*
11 * Testing strtok() for error conditions
12*/
13
14echo "*** Testing strtok() : error conditions ***\n";
15
16// Zero argument
17echo "\n-- Testing strtok() function with Zero arguments --\n";
18var_dump( strtok() );
19
20// More than expected number of arguments
21echo "\n-- Testing strtok() function with more than expected no. of arguments --\n";
22$str = 'sample string';
23$token = ' ';
24$extra_arg = 10;
25
26var_dump( strtok($str, $token, $extra_arg) );
27var_dump( $str );
28
29// Less than expected number of arguments
30echo "\n-- Testing strtok() with less than expected no. of arguments --\n";
31$str = 'string val';
32
33var_dump( strtok($str));
34var_dump( $str );
35
36echo "Done\n";
37?>
38--EXPECTF--
39*** Testing strtok() : error conditions ***
40
41-- Testing strtok() function with Zero arguments --
42
43Warning: strtok() expects at least 1 parameter, 0 given in %s on line %d
44NULL
45
46-- Testing strtok() function with more than expected no. of arguments --
47
48Warning: strtok() expects at most 2 parameters, 3 given in %s on line %d
49NULL
50string(13) "sample string"
51
52-- Testing strtok() with less than expected no. of arguments --
53bool(false)
54string(10) "string val"
55Done
56