Fix TypeError in CacheEventListener when event type mismatches#44
Merged
LordSimal merged 1 commit intoLordSimal:3.xfrom Jan 12, 2026
Merged
Conversation
Use defensive runtime type checking instead of strict PHP type hints for cache event handlers. This prevents TypeErrors when the dispatched event class doesn't match the expected type due to edge cases in CakePHP's cache event dispatching. The fix: - Changes parameter types from specific event classes to EventInterface - Adds instanceof checks at the start of each handler - Returns early if the event type doesn't match expectations This is a defensive programming approach that handles potential inconsistencies in the event system gracefully.
Owner
|
It feels to me like this is more of a downstream error of a event bug instead of an actual bug in this plugin. Would be awesome if there is some way to reproduce that. Especially since I just looked through all the events being dispatched in https://github.com/cakephp/cakephp/pull/18956/files and I can't figure out how something like with a wrong Do you maybe have a custom CacheEngine? |
Contributor
Author
|
I use redis |
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a TypeError that occurs when the dispatched cache event class doesn't match the expected type:
This can happen in edge cases when nested cache operations cause the
_eventClassproperty to be out of sync with the dispatched event name.Changes
EventInterfaceinstanceofchecks at the start of each handlerThis is a defensive programming approach that handles potential inconsistencies in the event system gracefully without crashing.
Test plan