@@ -1011,14 +1011,16 @@ class IdenticalNarrowingHelper
10111011
10121012 // a `$a::class` side falls back only where the old instanceof-style
10131013 // blocks would fire: a true context with a single class-name string
1014- // on the other side; everything else narrows generically
1014+ // or a `static::class`-like fetch on the other side; everything else
1015+ // narrows generically
10151016 bool contextTrue;
10161017 if (UNEXPECTED (!ctxTrue (context, contextTrue))) return zv::Val ();
10171018 if (contextTrue) {
10181019 for (int i = 0 ; i < 2 ; i++) {
10191020 zval *sideUnwrapped = i == 0 ? unwrappedLeft : unwrappedRight;
10201021 zval *side = i == 0 ? left : right;
10211022 zval *sideResult = i == 0 ? leftResult : rightResult;
1023+ zval *otherUnwrapped = i == 0 ? unwrappedRight : unwrappedLeft;
10221024 zval *otherResult = i == 0 ? rightResult : leftResult;
10231025 if (!isA (sideUnwrapped, PT_CLASS_CLASS_CONST_FETCH ) || !isA (classOf (sideUnwrapped), PT_CLASS_EXPR )) {
10241026 if (UNEXPECTED (EG (exception))) return zv::Val ();
@@ -1031,11 +1033,32 @@ class IdenticalNarrowingHelper
10311033 if (UNEXPECTED (otherType.isUndef ())) return zv::Val ();
10321034 zv::Val otherStrings = constantStringsOf (otherType.raw ());
10331035 if (UNEXPECTED (otherStrings.isUndef ())) return zv::Val ();
1034- if (countOf (otherStrings.raw ()) != 1 ) continue ;
1035- zval *otherString = firstOf (otherStrings.raw ());
1036- zv::Val value = constantStringValue (otherString);
1037- if (UNEXPECTED (value.isUndef ())) return zv::Val ();
1038- if (Z_TYPE_P (value.raw ()) == IS_STRING && ZSTR_LEN (Z_STR_P (value.raw ())) == 0 ) continue ;
1036+ bool singleNonEmpty = countOf (otherStrings.raw ()) == 1 ;
1037+ zval *otherString = NULL ;
1038+ zv::Val value;
1039+ if (singleNonEmpty) {
1040+ otherString = firstOf (otherStrings.raw ());
1041+ value = constantStringValue (otherString);
1042+ if (UNEXPECTED (value.isUndef ())) return zv::Val ();
1043+ singleNonEmpty = !(Z_TYPE_P (value.raw ()) == IS_STRING && ZSTR_LEN (Z_STR_P (value.raw ())) == 0 );
1044+ }
1045+ if (!singleNonEmpty) {
1046+ // $a::class === static::class narrows $a to the class-string's object type
1047+ bool otherIsClassConstFetch = isA (otherUnwrapped, PT_CLASS_CLASS_CONST_FETCH ) && isA (classOf (otherUnwrapped), PT_CLASS_NAME );
1048+ if (UNEXPECTED (EG (exception))) return zv::Val ();
1049+ if (otherIsClassConstFetch) {
1050+ zv::Val otherObjectType = typeCall (otherType.raw (), " getClassStringObjectType" , PT_LC (" getclassstringobjecttype" ));
1051+ if (UNEXPECTED (otherObjectType.isUndef ())) return zv::Val ();
1052+ zend_long isObject = trinaryByName (otherObjectType.raw (), " isObject" , PT_LC (" isobject" ));
1053+ if (UNEXPECTED (isObject < 0 )) return zv::Val ();
1054+ if (isObject == PT_TRI_YES ) {
1055+ zv::Val classTypes = createForSubject (classOf (sideUnwrapped), otherObjectType.raw (), context, evaluationScope);
1056+ if (UNEXPECTED (classTypes.isUndef ())) return zv::Val ();
1057+ return unionWith (std::move (classTypes), createSubjectTypes (evaluationScope, side, sideResult, otherType.raw (), context));
1058+ }
1059+ }
1060+ continue ;
1061+ }
10391062
10401063 bool known;
10411064 if (UNEXPECTED (!hasClass (value.raw (), known))) return zv::Val ();
0 commit comments