Skip to content

Instantly share code, notes, and snippets.

@trych
Created October 6, 2022 08:35
Show Gist options
  • Save trych/1b469a43cfe22cd29546155b168d94b5 to your computer and use it in GitHub Desktop.
Save trych/1b469a43cfe22cd29546155b168d94b5 to your computer and use it in GitHub Desktop.
Null error issue in argument expressions of e()
<?php
$poster = $video->poster()->toFile();
// das geht nicht, wenn $poster null ist, *obwohl* die var $poster existiert
// Call to a member function resize() on null
e($poster, Html::attr('poster', $poster->resize(1280)->url()));
// das hingegen funktioniert:
if($poster) echo Html::attr('poster', $poster->resize(1280)->url());
// und das hier funktioniert auch
echo $poster ? Html::attr('poster', $poster->resize(1280)->url()) : '';
// was auch funktioniert ist der nullsafe operator
e($poster, Html::attr('poster', $poster?->resize(1280)->url()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment