Fixed Code event listener hint considers falsy values as no hint

Xon

Well-known member
Affected version
2.2.12
When the listener cache is built, a falsy value is considered a non-valid hint.

PHP:
	public function getListenerCacheData()
	{
		$listeners = $this->finder('XF:CodeEventListener')
			->whereAddOnActive(['disableProcessing' => true])
			->where('active', 1)
			->order(['event_id', 'execute_order', 'addon_id'])
			->fetch();

		$cache = [];

		foreach ($listeners AS $listener)
		{
			$hint = $listener['hint'] ? $listener['hint'] : '_';
			$cache[$listener['event_id']][$hint][] = [$listener['callback_class'], $listener['callback_method']];
		}

		return $cache;
	}

Since $listener is an entity, it would also make sense to use -> property syntax instead of an array.

An explicit hint of _ should likely rejected in the CodeEventListener entity (just for admin edits?) to avoid surprises on the use of this sentinel value.
 
Thank you for reporting this and many other issues.

Some reports certainly smell valid from the details provided, but others I feel lack context. Like perhaps you might have run into issues in the wild but they aren't actually explained so it's difficult to assess the repercussions.

In this particular case, it should be patently obvious to anyone that a falsy value isn't going to work and I can't see a reason why a falsy value, even excusing the fact that clearly 0 wouldn't be valid even if you tried to use it, shouldn't be considered as "no hint".

I don't feel like there's a compelling reason to block _ as, once again, that would be a strange value to use, you shouldn't expect it to work and even if used, doesn't really have an unexpected impact.

Any further details or will it be safe to leave this as it is?
 
Generally these are (minor) issues discovered during support work or development of client/internal code.

It is just an odd foot-gun which if triggered takes exploration of why XF is behaving in that looks to an outsider as being odd while internally having a logic to it. In this case, inline documentation around falsy or _ would be useful.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.13).

Change log:
Fix behavior of falsy code event listener hints
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom