Jump to content

Featured Replies

Posted

Found a small bug which only seems to show when I have Whoops enabled.

This happened when viewing a member's profile in the ACP and an applications Notification configurationOptions function does NOT explicitly set a return.

Such as:

	public static function configurationOptions( \IPS\Member $member = NULL )
	{
		if ( $member === NULL or $member->modPermission( 'can_view_hidden_content' ) )
		{
			return [
				'my_notification' => [
					'type'              => 'standard',
					'notificationTypes' => ['my_notifiction'],
					'title'             => 'notifications__my_notification',
					'showTitle'         => FALSE,
					'description'       => 'notifications__my_notification_desc',
					'default'           => ['inline'],
					'disabled'          => ['email', 'push']
				]
			];
		}
	}

Could contain: Text

Could contain: Page, Text, File

Solved by Daniel F

Go to solution
  • Community Expert

What application is that code from? It's not from the default IPS code at least.

 

The problem is that the return array() code is inside the IF check, if the check fails nothing is returned. Adding a simple return at the end of the function is enough:

	public static function configurationOptions( \IPS\Member $member = NULL )
	{
		if ( $member === NULL or $member->modPermission( 'can_view_hidden_content' ) )
		{
			return [
				'my_notification' => [
					'type'              => 'standard',
					'notificationTypes' => ['my_notifiction'],
					'title'             => 'notifications__my_notification',
					'showTitle'         => FALSE,
					'description'       => 'notifications__my_notification_desc',
					'default'           => ['inline'],
					'disabled'          => ['email', 'push']
				]
			];
		}
		
		return array();
	}

 

  • Author
 

What application is that code from? It's not from the default IPS code at least.

 

The problem is that the return array() code is inside the IF check, if the check fails nothing is returned. Adding a simple return at the end of the function is enough:

	public static function configurationOptions( \IPS\Member $member = NULL )
	{
		if ( $member === NULL or $member->modPermission( 'can_view_hidden_content' ) )
		{
			return [
				'my_notification' => [
					'type'              => 'standard',
					'notificationTypes' => ['my_notifiction'],
					'title'             => 'notifications__my_notification',
					'showTitle'         => FALSE,
					'description'       => 'notifications__my_notification_desc',
					'default'           => ['inline'],
					'disabled'          => ['email', 'push']
				]
			];
		}
		
		return array();
	}

 

It's just an example which will trigger the Warning in Whoops. 🙂

  • Solution

The method should return an array (mentioned by phpdoc)

Unfortunately, there were no return types when IPS 4 was created, but they're now, so I guess the best thing to do here is to enforce it

Dr Evil GIF

 

Seems much more straightforward than including just another IMO unnecesary check for the methods return value.

  • Author
 

The method should return an array (mentioned by phpdoc)

Unfortunately, there were no return types when IPS 4 was created, but they're now, so I guess the best thing to do here is to enforce it

Dr Evil GIF

 

Seems much more straightforward than including just another IMO unnecesary check for the methods return value.

Developers don't always do what is in the manual. 🤪

Recently Browsing 0

  • No registered users viewing this page.