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