Skip to content

Conversation

@Carnicero90
Copy link
Contributor

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:

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());

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());
@taylorotwell taylorotwell merged commit e20db50 into laravel:12.x Sep 24, 2025
64 of 65 checks passed
tegos pushed a commit to tegos/laravel-framework that referenced this pull request Sep 28, 2025
…aravel#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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants