infojunkie / MantisBT-Slack

Slack integration for Mantis bug tracker
GNU General Public License v2.0
48 stars 37 forks source link

Function scope #34

Closed whiteflash34 closed 7 years ago

whiteflash34 commented 7 years ago

The following lines are incorrect:

` 'reporter_id' => function($bug) { return $this->get_user_name($bug->reporter_id); }, 'handler_id' => function($bug) { return empty($bug->handler_id) ? plugin_lang_get('no_user') : $this->get_user_name($bug->handler_id); },

`

they should be replaced with:

` 'reporter_id' => function($bug) use($self) { return $self->get_user_name($bug->reporter_id); }, 'handler_id' => function($bug) use($self) { return empty($bug->handler_id) ? plugin_lang_get('no_user') : $self->get_user_name($bug->handler_id); },

`

infojunkie commented 7 years ago

We've been using handler_id as a column since this plugin was created in 2014. Why exactly is this incorrect?

whiteflash34 commented 7 years ago

It's actually $this that's the issue, not hanlder_id. $this is not an object that is in scope of the function. It was causing a fatal error on MantisBT 2.5 when updating a ticket. Seems to work when creating and adding notes, but not updating.

infojunkie commented 7 years ago

Understood, but if we're using handler_id successfully, this means that the function works correctly. What PHP version are you using? I will test with Mantis 2.5.

infojunkie commented 7 years ago

Also, it's better to submit pull requests instead of showing code changes in the issue.

whiteflash34 commented 7 years ago

PHP Version 5.3.27. Agreed. I'll do a pull next time.

infojunkie commented 7 years ago

Using Mantis 2.5.1 and PHP 5.5.9-1ubuntu4.21 and the plugin works. I suggest you upgrade PHP.