1--TEST--
2Test imagecolorallocate() function : usage variations  - passing octal and hexa-decimal values
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7if(!function_exists('imagecreatetruecolor')) {
8    die('skip imagecreatetruecolor function is not available');
9}
10?>
11--FILE--
12<?php
13require __DIR__ . '/func.inc';
14
15echo "*** Testing imagecolorallocate() : usage variations ***\n";
16
17$im = imagecreatetruecolor(200, 200);
18$red = 10;
19$green = 10;
20$blue = 10;
21
22$values = array(
23      // octal integer data
24      "Octal 000" => 000,
25      "Octal 012" => 012,
26      "Octal -012" => -012,
27      "Octal 0377" => 0377,
28
29      // hexa-decimal integer data
30      "Hexa-decimal 0x0" => 0x0,
31      "Hexa-decimal 0xA" => 0xA,
32      "Hexa-decimal -0xA" => -0xA,
33      "Hexa-decimal 0xFF" => 0xFF,
34);
35
36// loop through each element of the array for blue
37foreach($values as $key => $value) {
38    echo "\n--$key--\n";
39
40    trycatch_dump(
41        fn() => imagecolorallocate($im, $value, $green, $blue),
42        fn() => imagecolorallocate($im, $red, $value, $blue),
43        fn() => imagecolorallocate($im, $red, $green, $value)
44    );
45};
46?>
47--EXPECT--
48*** Testing imagecolorallocate() : usage variations ***
49
50--Octal 000--
51int(2570)
52int(655370)
53int(657920)
54
55--Octal 012--
56int(657930)
57int(657930)
58int(657930)
59
60--Octal -012--
61!! [ValueError] imagecolorallocate(): Argument #2 ($red) must be between 0 and 255 (inclusive)
62!! [ValueError] imagecolorallocate(): Argument #3 ($green) must be between 0 and 255 (inclusive)
63!! [ValueError] imagecolorallocate(): Argument #4 ($blue) must be between 0 and 255 (inclusive)
64
65--Octal 0377--
66int(16714250)
67int(720650)
68int(658175)
69
70--Hexa-decimal 0x0--
71int(2570)
72int(655370)
73int(657920)
74
75--Hexa-decimal 0xA--
76int(657930)
77int(657930)
78int(657930)
79
80--Hexa-decimal -0xA--
81!! [ValueError] imagecolorallocate(): Argument #2 ($red) must be between 0 and 255 (inclusive)
82!! [ValueError] imagecolorallocate(): Argument #3 ($green) must be between 0 and 255 (inclusive)
83!! [ValueError] imagecolorallocate(): Argument #4 ($blue) must be between 0 and 255 (inclusive)
84
85--Hexa-decimal 0xFF--
86int(16714250)
87int(720650)
88int(658175)
89