@@ -91,9 +91,16 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
9191 if (count ($ constantStrings ) > 0 ) {
9292 $ results = [];
9393 foreach ($ constantStrings as $ constantString ) {
94- $ items = $ encoding === null
95- ? str_split ($ constantString ->getValue (), $ splitLength )
96- : @mb_str_split ($ constantString ->getValue (), $ splitLength , $ encoding );
94+ $ value = $ constantString ->getValue ();
95+
96+ if ($ encoding === null && $ value === '' ) {
97+ // Simulate the str_split call with the analysed PHP Version instead of the runtime one.
98+ $ items = $ this ->phpVersion ->strSplitReturnsEmptyArrayOnEmptyString () ? [] : ['' ];
99+ } else {
100+ $ items = $ encoding === null
101+ ? str_split ($ value , $ splitLength )
102+ : @mb_str_split ($ value , $ splitLength , $ encoding );
103+ }
97104
98105 $ results [] = self ::createConstantArrayFrom ($ items , $ scope );
99106 }
@@ -104,7 +111,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
104111
105112 $ isInputNonEmptyString = $ stringType ->isNonEmptyString ()->yes ();
106113
107- if ($ isInputNonEmptyString || $ this ->phpVersion ->strSplitReturnsEmptyArray ()) {
114+ if ($ isInputNonEmptyString || $ this ->phpVersion ->strSplitReturnsEmptyArrayOnEmptyString ()) {
108115 $ returnValueType = TypeCombinator::intersect (new StringType (), new AccessoryNonEmptyStringType ());
109116 } else {
110117 $ returnValueType = new StringType ();
@@ -115,7 +122,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
115122 // Non-empty-string will return an array with at least an element
116123 $ isInputNonEmptyString
117124 // str_split('', 1) returns [''] on old PHP version and [] on new ones
118- || ($ functionReflection ->getName () === 'str_split ' && !$ this ->phpVersion ->strSplitReturnsEmptyArray ())
125+ || ($ functionReflection ->getName () === 'str_split ' && !$ this ->phpVersion ->strSplitReturnsEmptyArrayOnEmptyString ())
119126 ) {
120127 $ returnType = TypeCombinator::intersect ($ returnType , new NonEmptyArrayType ());
121128 }
0 commit comments