1--TEST-- 2Test mb_substitute_character() function : usage variation 3--SKIPIF-- 4<?php 5extension_loaded('mbstring') or die('skip'); 6?> 7--FILE-- 8<?php 9declare(strict_types=1); 10 11echo "*** Testing mb_substitute_character(): various types in strict typing mode ***\n"; 12 13// Initialise function arguments not being substituted (if any) 14 15//get an unset variable 16$unset_var = 10; 17unset ($unset_var); 18 19// define some classes 20class classWithToString 21{ 22 public function __toString() { 23 return "Class A object"; 24 } 25} 26 27class classWithoutToString 28{ 29} 30 31// heredoc string 32$heredoc = <<<EOT 33hello world 34EOT; 35 36// get a resource variable 37$fp = fopen(__FILE__, "r"); 38 39// add arrays 40$index_array = array (1, 2, 3); 41$assoc_array = array ('one' => 1, 'two' => 2); 42 43//array of values to iterate over 44$inputs = array( 45 46 // int data 47 'int 0' => 0, 48 'int 1' => 1, 49 'int 12345' => 12345, 50 'int -12345' => -2345, 51 52 // float data 53 'float 10.5' => 10.5, 54 'float -10.5' => -10.5, 55 'float 10.0e19' => 10.0e19, // Cannot be represented as int 56 'float -10.0e19' => -10.0e19, // Cannot be represented as int 57 'float .5' => .5, 58 59 // array data 60 'empty array' => array(), 61 'int indexed array' => $index_array, 62 'associative array' => $assoc_array, 63 'nested arrays' => array('foo', $index_array, $assoc_array), 64 65 // null data 66 'uppercase NULL' => NULL, 67 'lowercase null' => null, 68 69 // boolean data 70 'lowercase true' => true, 71 'lowercase false' =>false, 72 'uppercase TRUE' =>TRUE, 73 'uppercase FALSE' =>FALSE, 74 75 // empty data 76 'empty string DQ' => "", 77 'empty string SQ' => '', 78 79 // string data 80 'string DQ' => "string", 81 'string SQ' => 'string', 82 'mixed case string' => "sTrInG", 83 'heredoc' => $heredoc, 84 85 // object data 86 'instance of classWithToString' => new classWithToString(), 87 'instance of classWithoutToString' => new classWithoutToString(), 88 89 // undefined data 90 'undefined var' => @$undefined_var, 91 92 // unset data 93 'unset var' => @$unset_var, 94); 95 96// loop through each element of the array for substchar 97 98mb_internal_encoding('utf-8'); 99foreach($inputs as $key =>$value) { 100 echo "--$key--\n"; 101 try { 102 var_dump( mb_substitute_character($value) ); 103 } catch (\ValueError|\TypeError $e) { 104 echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; 105 } 106} 107 108fclose($fp); 109 110?> 111--EXPECT-- 112*** Testing mb_substitute_character(): various types in strict typing mode *** 113--int 0-- 114bool(true) 115--int 1-- 116bool(true) 117--int 12345-- 118bool(true) 119--int -12345-- 120ValueError: mb_substitute_character(): Argument #1 ($substitute_character) is not a valid codepoint 121--float 10.5-- 122TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, float given 123--float -10.5-- 124TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, float given 125--float 10.0e19-- 126TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, float given 127--float -10.0e19-- 128TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, float given 129--float .5-- 130TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, float given 131--empty array-- 132TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, array given 133--int indexed array-- 134TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, array given 135--associative array-- 136TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, array given 137--nested arrays-- 138TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, array given 139--uppercase NULL-- 140int(12345) 141--lowercase null-- 142int(12345) 143--lowercase true-- 144TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, bool given 145--lowercase false-- 146TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, bool given 147--uppercase TRUE-- 148TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, bool given 149--uppercase FALSE-- 150TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, bool given 151--empty string DQ-- 152ValueError: mb_substitute_character(): Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint 153--empty string SQ-- 154ValueError: mb_substitute_character(): Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint 155--string DQ-- 156ValueError: mb_substitute_character(): Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint 157--string SQ-- 158ValueError: mb_substitute_character(): Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint 159--mixed case string-- 160ValueError: mb_substitute_character(): Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint 161--heredoc-- 162ValueError: mb_substitute_character(): Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint 163--instance of classWithToString-- 164TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, classWithToString given 165--instance of classWithoutToString-- 166TypeError: mb_substitute_character(): Argument #1 ($substitute_character) must be of type string|int|null, classWithoutToString given 167--undefined var-- 168int(12345) 169--unset var-- 170int(12345) 171