Replies: 1 comment 1 reply
-
Does this behavior not exist in spatie's once? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've been using the new once() helper in Laravel 11, and I found behavior that surprised me.
Now when I call
ChildA::load()
and thenChildB::load()
, I get the result fromChildA
both times because the once hash only takes into account the class that it is in, not the class that it was called from. It putsParent::class
into the hash but notChildA::class
.If they weren't static, I'd call
(new ChildA)->load()
and(new ChildB)->load()
and get the correct results because they are different instances.There is nothing about this in the documentation (nor, indeed, anything about using once() in static methods at all). I think it should be possible to get the calling class from the callable by reflection.
This behavior feels like a bug to me. I definitely expected it to work differently, but that's my personal opinion. What do you think?
Beta Was this translation helpful? Give feedback.
All reactions