Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted February 23, 20232 yr 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'] ] ]; } }
February 23, 20232 yr 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(); }
February 23, 20232 yr 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. 🙂
February 23, 20232 yr 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 Seems much more straightforward than including just another IMO unnecesary check for the methods return value.
February 23, 20232 yr 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 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. 🤪