1--TEST--
2mb_check_encoding() - Circular references
3--SKIPIF--
4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5--FILE--
6<?php
7ini_set('default_charset', 'UTF-8');
8// Valid - Detects recursion
9$str = "Japanese UTF-8 text. 日本語のUTF-8テキスト";
10$arr = [1234, 12.34, TRUE, FALSE, NULL, $str, 'key'=>$str, $str=>'val'];
11$tmp = &$arr;
12$arr[] = $tmp;
13var_dump(mb_check_encoding($str), mb_check_encoding($arr));
14
15// Invalid - Return false due to short circuit check
16$str = "Japanese UTF-8 text. 日本語\xFE\x01\x02のUTF-8テキスト";
17$arr1 = [1234, 12.34, TRUE, FALSE, NULL, 'key'=>$str, $str=>'val'];
18$tmp = &$arr1;
19$arr1[] = $tmp;
20$arr2 = [1234, 12.34, TRUE, FALSE, NULL, $str=>'val'];
21$tmp = &$arr2;
22$arr2[] = $tmp;
23var_dump(mb_check_encoding($str), mb_check_encoding($arr1),  mb_check_encoding($arr2));
24?>
25--EXPECTF--
26Warning: mb_check_encoding(): Cannot not handle circular references in %s on line %d
27bool(true)
28bool(false)
29bool(false)
30bool(false)
31bool(false)
32