Skip to content

explode issue using Jetstream with PHP 8.1 #1121

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

Closed
n3rdbuddy opened this issue Aug 12, 2022 · 4 comments
Closed

explode issue using Jetstream with PHP 8.1 #1121

n3rdbuddy opened this issue Aug 12, 2022 · 4 comments

Comments

@n3rdbuddy
Copy link

  • Jetstream Version: ^2.10
  • Jetstream Stack: Livewire
  • Uses Teams: yes
  • Laravel Version: ^9.19
  • PHP Version: 8.1
  • Database Driver & Version: MySQL

Description:

Disclaimer: I'm sharing not complaining... ;)

line 74 on the HasProfilePhoto trait throws an error related to the explode function on php 8.1

LOG.warning: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /var/www/html/vendor/laravel/jetstream/src/HasProfilePhoto.php on line 74

Fix

change
explode(' ', $this->name)
to
explode(' ', $this->name ?? '')

note: Since this vale comes from the DB it can sometimes be null which is deprecated for explode in PHP 8.1. Passing an empty string instead of null seems to work.

Hope this helps.

Steps To Reproduce:

When using Jetstream + HasProfilePhoto Trait on PHP 8.1 and no profile image has been assigned to the user.

@timacdonald
Copy link
Member

timacdonald commented Aug 14, 2022

The users' name is not nullable in Jetstream.

If you have changed this in your own application you should consider handing this in your application. Likely more of Jetstream is also in a bad state if the users name is also allowed to be null in your application i.e. views where the users' name is visible.

@n3rdbuddy
Copy link
Author

The users' name is not nullable in Jetstream.

If you have changed this in your own application you should consider handing this in your application. Likely more of Jetstream is also in a bad state if the users name is also allowed to be null in your application i.e. views where the users' name is visible.

I have built my own profile photo implementation as I would prefer to avoid editing vendor code unless intended. I ran into the error in my app and shared my findings to save someone else the hours of research it took me to figure out. If you intend to say that there is a better place to share this information specific to code I believed was meant to be used as-is, then I'm happy to be pointed in that direction. On the other hand, I'm fine considering it moot since I've found a solution for my own project. I appreciate you taking the time to review the information.

@driesvints
Copy link
Member

Right now, the user's name is required as @timacdonald explained. If you want to change this you can maybe attempt a PR. Sorry

@n3rdbuddy
Copy link
Author

Right now, the user's name is required as @timacdonald explained. If you want to change this you can maybe attempt a PR. Sorry

My post has nothing to do with the user's name. After registration the user's profile photo path is not set. Visiting the profile page call's the explode function via defaultProfilePhotoUrl() function on the HasProfilePhoto Trait. At this point no profile photo has been set so the value coming from the DB is null. I have provided as much info as is needed to recreate the issue and the solution that worked for my project. Like I stated before I only intended to save the people who would run into the error like I did some research time.

I appreciate the exchange of ideas, but this has taken more of my time than I intended. Hope the info helped\helps someone, Or it can be deleted if decided that it's irrelevant.

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

No branches or pull requests

3 participants