Skip to content

Commit

Permalink
Align PHP 8.1 behavior (#36262)
Browse files Browse the repository at this point in the history
While not explicitly allowed in the PHPDoc, `e(null)` returns `""` with PHP < 8.1
On PHP >= 8.1, an error is thrown if `null` is passed to `htmlspecialchars`.

As `e(null)` is still a common case (for instance via Blade in view templates) I think it's safest to just default the `null` value to an empty string to get the same behavior with the next PHP minor version.
  • Loading branch information
kylekatarnls authored Feb 15, 2021
1 parent 0146a3b commit aedc04c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function class_uses_recursive($class)
/**
* Encode HTML special characters in a string.
*
* @param \Illuminate\Contracts\Support\DeferringDisplayableValue|\Illuminate\Contracts\Support\Htmlable|string $value
* @param \Illuminate\Contracts\Support\DeferringDisplayableValue|\Illuminate\Contracts\Support\Htmlable|string|null $value
* @param bool $doubleEncode
* @return string
*/
Expand All @@ -115,7 +115,7 @@ function e($value, $doubleEncode = true)
return $value->toHtml();
}

return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', $doubleEncode);
return htmlspecialchars($value ?? '', ENT_QUOTES, 'UTF-8', $doubleEncode);
}
}

Expand Down

0 comments on commit aedc04c

Please sign in to comment.