Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1400,14 +1400,21 @@ public function getClassConstFetchTypeByReflection(Name|Expr $class, string $con
if ($reflectionConstant->getType() !== null) {
$nativeType = TypehintHelper::decideTypeFromReflection($reflectionConstant->getType(), selfClass: $constantClassReflection);
}
$phpDocType = $constantClassReflection->getConstantPhpDocType($constantName);
$resolvedType = $this->transformStaticType($this->constantResolver->resolveClassConstantType(
$constantClassReflection->getName(),
$constantName,
$constantType,
$nativeType,
$nativeTypesPromoted ? null : $constantClassReflection->getConstantPhpDocType($constantName),
$nativeTypesPromoted ? null : $phpDocType,
), $fetchedOnType);
$this->classConstantValueTypeCache[$cacheKey] = $resolvedType;
if ($phpDocType === null) {
// the PHPDoc type is the only input that differs, so both variants share the resolved type
$this->classConstantValueTypeCache[$resolvingName] = $resolvedType;
$this->classConstantValueTypeCache[$resolvingName . '#native'] = $resolvedType;
} else {
$this->classConstantValueTypeCache[$cacheKey] = $resolvedType;
}
$types[] = $resolvedType;
unset($this->currentlyResolvingClassConstant[$resolvingName]);
continue;
Expand Down
17 changes: 13 additions & 4 deletions turbo-ext/src/InitializerExprTypeResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2623,11 +2623,20 @@ class InitializerExprTypeResolver
}
}
IETR_VAL(className, classReflectionName(constantClassReflection.raw()));
zv::Val phpDocType = nativeTypesPromoted ? zv::Val::null() : callOn(constantClassReflection.raw(), mGetConstantPhpDocType, 1, constantName);
if (UNEXPECTED(phpDocType.isUndef())) return zv::Val();
IETR_VAL(resolvedClassConstantType, resolveClassConstantType(prop(slots::constantResolver), className.raw(), constantName, constantType.raw(), nativeType.raw(), phpDocType.raw()));
IETR_VAL(phpDocType, callOn(constantClassReflection.raw(), mGetConstantPhpDocType, 1, constantName));
zval nullPhpDocType;
ZVAL_NULL(&nullPhpDocType);
IETR_VAL(resolvedClassConstantType, resolveClassConstantType(prop(slots::constantResolver), className.raw(), constantName, constantType.raw(), nativeType.raw(), nativeTypesPromoted ? &nullPhpDocType : phpDocType.raw()));
IETR_VAL(resolvedType, transformStaticType(resolvedClassConstantType.raw(), fetchedOnType.raw()));
writeArrayProperty(slots::classConstantValueTypeCache, cacheKey, resolvedType.raw());
if (Z_TYPE_P(phpDocType.raw()) == IS_NULL) {
/* the PHPDoc type is the only input that differs, so both variants share the resolved type */
zend_string *nativeCacheKey = zend_string_concat2(ZSTR_VAL(resolvingName), ZSTR_LEN(resolvingName), "#native", 7);
zv::Val nativeCacheKeyHold = zv::Val::adoptString(nativeCacheKey);
writeArrayProperty(slots::classConstantValueTypeCache, resolvingName, resolvedType.raw());
writeArrayProperty(slots::classConstantValueTypeCache, nativeCacheKey, resolvedType.raw());
} else {
writeArrayProperty(slots::classConstantValueTypeCache, cacheKey, resolvedType.raw());
}
types.push(zv::Ref(resolvedType.raw()));
unsetArrayProperty(slots::currentlyResolvingClassConstant, resolvingName);
continue;
Expand Down
Loading