1--TEST--
2Test tempnam() function: usage variations - test prefix maximum size
3--SKIPIF--
4<?php
5if (PHP_OS_FAMILY === 'Windows') {
6    die("skip Do not run on Windows");
7}
8?>
9--FILE--
10<?php
11/* Testing the maximum prefix size */
12
13echo "*** Testing tempnam() maximum prefix size ***\n";
14$file_path = __DIR__."/tempnamVar9";
15mkdir($file_path);
16
17$pre_prefix = "begin_";
18$post_prefix = "_end";
19$fixed_length = strlen($pre_prefix) + strlen($post_prefix);
20/* An array of prefixes */
21$names_arr = [
22  $pre_prefix . str_repeat("x", 7) . $post_prefix,
23  $pre_prefix . str_repeat("x", 63 - $fixed_length) . $post_prefix,
24  $pre_prefix . str_repeat("x", 64 - $fixed_length) . $post_prefix,
25  $pre_prefix . str_repeat("x", 65 - $fixed_length) . $post_prefix,
26  $pre_prefix . str_repeat("x", 300) . $post_prefix,
27];
28
29foreach($names_arr as $i=>$prefix) {
30    echo "-- Iteration $i --\n";
31    try {
32        $file_name = tempnam("$file_path", $prefix);
33    } catch (Error $e) {
34        echo $e->getMessage(), "\n";
35        continue;
36    }
37
38    $base_name = basename($file_name);
39    echo "File name is => ", $base_name, "\n";
40    echo "File name length is => ", strlen($base_name), "\n";
41
42    if (file_exists($file_name)) {
43        unlink($file_name);
44    }
45}
46rmdir($file_path);
47
48?>
49--CLEAN--
50<?php
51$file_path = __DIR__."/tempnamVar9";
52if (file_exists($file_path)) {
53    array_map('unlink', glob($file_path . "/*"));
54    rmdir($file_path);
55}
56?>
57--EXPECTF--
58*** Testing tempnam() maximum prefix size ***
59-- Iteration 0 --
60File name is => begin_%rx{7}%r_end%r.{6}%r
61File name length is => 23
62-- Iteration 1 --
63File name is => begin_%rx{53}%r_end%r.{6}%r
64File name length is => 69
65-- Iteration 2 --
66File name is => begin_%rx{54}%r_en%r.{6}%r
67File name length is => 69
68-- Iteration 3 --
69File name is => begin_%rx{55}%r_e%r.{6}%r
70File name length is => 69
71-- Iteration 4 --
72File name is => begin_%rx{57}%r%r.{6}%r
73File name length is => 69
74