-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Exclude property hooks on return of Model::__sleep() #57557
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
Exclude property hooks on return of Model::__sleep() #57557
Conversation
|
Is there a reason, you didn't just replace |
|
@shaedrich Yes, I saw that, there are too many reasons:
The maintainers always will try keep the things simple and use the same approach. |
There's always a first time. If that wasn't so, Laravel would still use PHP 5.3. With
|
|
This honestly feels like the safest solution I've seen thus far. |
@rafaelqueiroz Hey you are saying "be nice" but also at the same time saying "get out of my way", "freak show", "should read more before they talk", and saying people aren't looking deep into the issue. Including such "un-nice" language in the same message as telling people to "be nice" comes across as rather duplicitous. Being more respectful is something everyone, including myself, should try to do, especially when collaborating and speaking through written English where so much context and inflection is missing (and English isn't everyone's first language). |
|
@AndrewMast sure thing, you're right, I tried explain, doesn't work and I almost leave as it which was the best. Anyway, you're right, sorry for it and thank you. |
|
@rafaelqueiroz congratulations. Your solution got merged. The fastest solution is to leave it as it was. The active reacord does not get along with property hooks. For someone that will use php 8.4 and will NOT use property hooks, the serialization will take a small hit in terms of performance. Whoever would use property hooks in the model, overriding the __sleep would had been the best solution. And to make that even simpler, that return could had been extracted into a protected function that could be overridden in a trait or a base model. @shaedrich There were numerous attempts with get_mangled_object_vars that were rejected before. |
I know. I just tried to get a good explanation since Taylor isn't known for these. I brought good points that weren't refuted yet.
My thoughts exactly. Thank you, @AndrewMast 👍🏻 My choice of words might not have been ideal, but I didn't write in that direct rudeness that was expressed towards the two of us. However, as English is not native language of many, both sides might phrase things suboptimal as the other side might misinterpret it. |
|
@rafaelqueiroz check out this question inspired by your PR being merged #31778 (comment) |
|
@marius-ciclistu to me, this is completely random, It seems like a lost cause from 2020, good luck. |
|
@rafaelqueiroz Thank you for the inspiration and sorry for upsetting you. It lead to that good ideea for avoiding casts but still having casts via property hooks:) |
|
Hey @rafaelqueiroz, how would you feel following up with an optimisation PR as below? It doesn't change your approach. But it avoids some extra work and extra memory usage:
$keys = [];
if (version_compare(PHP_VERSION, '8.4.0') >= 0) {
foreach ((new \ReflectionClass($this))->getProperties() as $property) {
if ($property->hasHooks() === false) {
$keys[] = $property->getName();
}
}
} else {
$keys = array_keys(get_object_vars($this));
}
return $keys;It's not a massive increase, but I believe if we can add a new feature in a more optimised way we should do so. Things add up. ✌️ |
|
Extracting that into a method + early returns would empower the developer that does not use hooks in model to avoid that reflection with an override and make the code cleaner: protected function getPropertiesForSerialization(): array
{
if (version_compare(PHP_VERSION, '8.4.0') < 0) {
return \array_keys(\get_object_vars($this));
}
$keys = [];
foreach ((new \ReflectionClass($this))->getProperties() as $property) {
if (!$property->hasHooks()) {
$keys[] = $property->getName();
}
}
return $keys;
} |
|
@marius-ciclistu sure, adds another advantage in top. 👍 Let's see if @rafaelqueiroz wants to PR it otherwise you or I can make an attempt. |
|
@NickSdot my work is done here, you can do and check if the maintainers will accept. |
From 57357