1--TEST--
2substringData() negative arguments (mod 32)
3--EXTENSIONS--
4dom
5--SKIPIF--
6<?php
7if (PHP_INT_SIZE === 4) die('skip not for 32-bit');
8?>
9--FILE--
10<?php
11
12echo "--- Modern behaviour ---\n";
13
14$dom = Dom\HTMLDocument::createEmpty();
15$comment = $dom->createComment("foobarbaz");
16var_dump($comment->substringData(0, -1));
17echo $dom->saveHtml($comment), "\n";
18var_dump($comment->substringData(2, -(2**32 - 2)));
19echo $dom->saveHtml($comment), "\n";
20var_dump($comment->substringData(-(2**32 - 2), 2));
21echo $dom->saveHtml($comment), "\n";
22
23echo "--- Legacy behaviour ---\n";
24
25$dom = new DOMDocument;
26$comment = $dom->createComment("foobarbaz");
27try {
28    var_dump($comment->substringData(0, -1));
29} catch (DOMException $e) {
30    echo $e->getMessage(), "\n";
31}
32echo $dom->saveHtml($comment), "\n";
33try {
34    var_dump($comment->substringData(2, -(2**32 - 2)));
35} catch (DOMException $e) {
36    echo $e->getMessage(), "\n";
37}
38echo $dom->saveHtml($comment), "\n";
39try {
40    var_dump($comment->substringData(-(2**32 - 2), 2));
41} catch (DOMException $e) {
42    echo $e->getMessage(), "\n";
43}
44echo $dom->saveHtml($comment), "\n";
45
46?>
47--EXPECT--
48--- Modern behaviour ---
49string(9) "foobarbaz"
50<!--foobarbaz-->
51string(2) "ob"
52<!--foobarbaz-->
53string(2) "ob"
54<!--foobarbaz-->
55--- Legacy behaviour ---
56Index Size Error
57<!--foobarbaz-->
58Index Size Error
59<!--foobarbaz-->
60Index Size Error
61<!--foobarbaz-->
62