Skip to content

Commit e20db50

Browse files
authored
Fix: Handle non-string returns from Htmlable::toHtml() in e() helper (#57157)
This adds null coalescing to maintain backward compatibility when Htmlable::toHtml() returns non-string values. **Breaking Change Context:** The addition of explicit `: string` return type creates a BC break because Htmlable::toHtml() only has PHPDoc type hints, not runtime enforcement. IMHO it should probably be reverted, this commit provides at least some backward compatibility. **Example of previously valid code that now breaks:** ```php class CustomHtmlable implements Htmlable { public function toHtml() { // Valid before: PHPDoc says @return string but no runtime enforcement return $this->hasContent() ? $this->content : null; } } // This worked before but now causes TypeError echo e(new CustomHtmlable());
1 parent 6090522 commit e20db50

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Illuminate/Support/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function e($value, $doubleEncode = true): string
127127
}
128128

129129
if ($value instanceof Htmlable) {
130-
return $value->toHtml();
130+
return $value->toHtml() ?? '';
131131
}
132132

133133
if ($value instanceof BackedEnum) {

0 commit comments

Comments
 (0)