-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[12.x] Fix serialization issue with PHP property hooks #57443
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
Conversation
|
Hello, @crynobone Is there any dependency? here is the error |
|
@Sajid-al-islam We see you are at least the 3rd one to attempt this change.
|
|
@macropay-solutions
|
Thank you.
Yes and this is making php attribute hooks in active record just a happy flow usage (coupled with the fact that arrays are not fully supported either). But that is not a stopper for this PR. Laravel is full of happy flows.EE UPDATE class A {
public $public = 1;
protected $protected = 2;
private $private = 3;
}
class B extends A {
private $private = 4;
public function showVars() {
var_dump(get_object_vars($this));
var_dump(get_mangled_object_vars($this));
}
}
echo '<pre>';
$obj = new B();
$obj->dynamic = 5;
$obj->showVars();DEPRECATED Creation of dynamic property B::$dynamic is deprecated on line number 17
It looks that the results are not exactly the same. |
|
You're right, my bad, get_mangled_object_vars() includes parent class private properties with prefixes. However, this doesn't negatively impact Laravel models since they don't use conflicting private properties across inheritance. The real issue is property hooks causing crashes, which this fixes. Although get_mangled_object_vars properly preserves inherited properties during serialization, As all the old test cases passed from laravel framework, I think it can be merged, let's see what Tyler has to say. |
|
I don't think we're really thinking this through - we're just hoping this works and crossing our fingers. I need someone to really dig into it deeply and give a considered solution (even if it is this solution) that is well explained. |
Fixes #57357
Fixes serialization errors when using PHP 8.4 property hooks in Eloquent models. When models with property hooks a serialized, Laravel throws:
serialize(): "property_name" returned as member variable from __sleep() but does not exist.Property hooks create virtual properties without actual storage. The current
__sleep()usesget_object_vars()which includes these virtual properties, causing serialization to fail.Solution: Changed
get_object_vars($this)toget_mangled_object_vars($this)inModel::__sleep(). This only returns properties with actual storage, excluding virtual property hooks.Tests: Added comprehensive coverage in
EloquentModelPropertyHooksTest.phpfor getter hooks, setter hooks, multiple hooks, mixed properties, and queue scenarios.