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

Getting __PHP_Incomplete_Class when unserializing third party classes #3

Closed
Ghost1032 opened this issue Sep 18, 2022 · 1 comment · Fixed by #4
Closed

Getting __PHP_Incomplete_Class when unserializing third party classes #3

Ghost1032 opened this issue Sep 18, 2022 · 1 comment · Fixed by #4
Labels
documentation Improvements or additions to documentation

Comments

@Ghost1032
Copy link
Contributor

Ghost1032 commented Sep 18, 2022

Code:

from phpserialize import serialize,unserialize
from phpserialize.decorators import namespace


@namespace('Faker')
class Generator:
    protected_formatters = {'dispatch': 'system'}


@namespace('Illuminate\Broadcasting')
class PendingBroadcast:
    protected_event = 'ls'
    protected_events = Generator()


a = serialize(PendingBroadcast())
print(a)
s = unserialize(a)
print(s)

Result:
image

This also happens when third-party classes extend PHP_Class.

Possible causes:
Code here
image

In unserialize.py#_handle_object(), the for loop doesn't take cls.__namespace__ into consideration, while serialize.py#_handle_attr() does.

@frankli0324
Copy link
Owner

frankli0324 commented Sep 18, 2022

unserialize 的对象需要继承 PHP_Class类:

from phpserialize import serialize, unserialize, PHP_Class

class PendingBroadcast(PHP_Class):
    protected_event = 'ls'
    protected_events = Generator()

a = serialize(PendingBroadcast())
print(a)
s = unserialize(a)
print(s)

一来是为了防止递归遍历object子类产生side effect,二来是让编写者“知道自己在干嘛”

关于namespace, known, will fix.

@frankli0324 frankli0324 added the documentation Improvements or additions to documentation label Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants