Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
TDBF Posted February 23, 2023 Posted February 23, 2023 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'] ] ]; } } teraßyte 1
teraßyte Posted February 23, 2023 Posted February 23, 2023 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(); }
TDBF Posted February 23, 2023 Author Posted February 23, 2023 1 hour ago, teraßyte said: 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 Daniel F Posted February 23, 2023 Solution Posted February 23, 2023 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. TDBF and SeNioR- 2
TDBF Posted February 23, 2023 Author Posted February 23, 2023 18 minutes ago, Daniel F said: 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. 🤪 SeNioR- and Daniel F 2
Recommended Posts