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

unserialize(): Error at offset #52

Closed
zhengwhizz opened this issue Jul 7, 2020 · 6 comments
Closed

unserialize(): Error at offset #52

zhengwhizz opened this issue Jul 7, 2020 · 6 comments
Labels
needs more info question Further information is requested

Comments

@zhengwhizz
Copy link

in laravel version "version": "v7.14.1", i got this error, i found databse notification field data is not right,
O:41:"App\Notifications\AppointmentNotification":10:{s:11:"
it's missing something. Why?
i have a Appointment model to store user's appoinment,
and how can i get the notification by Appointment id? if user change the appointment time, i need to reschedule the notification, i only can get the notification by user id / notification type

@atymic
Copy link
Collaborator

atymic commented Jul 16, 2020

Is it possible that you renamed or moved the class?

@atymic atymic added question Further information is requested needs more info labels Jul 16, 2020
@zFly
Copy link

zFly commented Aug 11, 2020

Hello,

I experienced exactly the same error, and fixed it using the fix-null-bytes branch from this pull request.

Writing serialize(new PaymentReminderNotification($this->order)); returns the expected serialized string

"O:45:"App\Notifications\PaymentReminderNotification":9:{s:8:"\x00*\x00order";O:45:"Illuminate\Contracts\Database\ModelIdentifier":4:{s:5:"class";s:16:"App\Models\Order";s:2:"id";s:36:"bfac1542-4669-3822-89a5-ec2aa1cd7add";s:9:"relations";a:0:{}s:10:"connection";s:5:"pgsql";}s:2:"id";N;s:6:"locale";N;s:10:"connection";N;s:5:"queue";N;s:15:"chainConnection";N;s:10:"chainQueue";N;s:5:"delay";N;s:7:"chained";a:0:{}}"

But after storing it into my pgsql DB the string gets cut of

"O:45:\"App\\Notifications\\PaymentReminderNotification\":9:{s:8:\""

Are there any plans to support pgsql DBs or merge the pull request?

@korridor
Copy link

I am having the same problem as @zFly.

I researched the problem a bit and I think the problem is that the response of serialize() should not be written to a database field with a text type.
A quote from the PHP documentation of serialize:

Note that this is a binary string which may include null bytes, and needs to be stored and handled as such. For example, serialize() output should generally be stored in a BLOB field in a database, rather than a CHAR or TEXT field.

According to this comment this is only a problem if you use private or protected properties.

@atymic
Copy link
Collaborator

atymic commented Sep 10, 2020

Could we use a blob field to avoid this issue?

@atymic atymic mentioned this issue Sep 10, 2020
5 tasks
@korridor
Copy link

@atymic I think so, but I think the advantage of saving the serialized object to TEXT is that it is semi-readable.
Maybe something like this would work: https://github.com/illuminate/cache/blob/7aacad834d7472b19a590f4f2fc0e413cf0efd83/DatabaseStore.php#L356

@atymic
Copy link
Collaborator

atymic commented Sep 10, 2020

Closed in #64
And will release in v2 :)

@atymic atymic closed this as completed Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants