Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to a member function format() on null #526

Open
pcbal opened this issue Nov 2, 2022 · 4 comments
Open

Call to a member function format() on null #526

pcbal opened this issue Nov 2, 2022 · 4 comments
Labels

Comments

@pcbal
Copy link

pcbal commented Nov 2, 2022

What steps will reproduce the problem?

install demo create user admin add a post add tag click on tag link

What is the expected result?

tag link should lead to tag page

What do you get instead?

format() error on line getPublishedAt()

Additional info

Q A
Version 1.0.?
PHP version 8.1.11
Operating system Linux (Ubuntu 22.04 LTS)
Server Inbuilt DB used
17:48:57_02_11_2022_*
@rossaddison
Copy link
Contributor

Hi, try this

echo Html::span(empty($post
        ->getPublishedAt()) ? '' : $post
        ->getPublishedAt() 
        ->format('H:i d.m.Y'));

@xepozz
Copy link
Contributor

xepozz commented Nov 3, 2022

Hi, try this

echo Html::span(empty($post
        ->getPublishedAt()) ? '' : $post
        ->getPublishedAt() 
        ->format('H:i d.m.Y'));

Also you can try a null-safe operator:

echo Html::span($post->getPublishedAt()?->format('H:i d.m.Y'));

But I suggest to find more convenient workaround and change the view's logic because you may get by {user} at output there.

@pcbal
Copy link
Author

pcbal commented Nov 3, 2022

Both approaches above work well.

@rossaddison
Copy link
Contributor

Brilliant! Thank you for your contribution pcbal. I will try xepozz's suggestion on issue #462. Desperately looking for simplification of issue 462 into a simple 'save' instead of separate 'add' and 'edit' functions even though my solution works.

@samdark samdark added the type:bug Bug label Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants