tessus / mwExtensionMantis

MediaWiki Extension:Mantis
https://www.mediawiki.org/wiki/Extension:Mantis
GNU General Public License v2.0
2 stars 6 forks source link

"Use of undefined constant dbcontext" #31

Closed pedwik closed 6 years ago

pedwik commented 7 years ago

I am testing the extension on MW 1.29.1 but get the following error when opening a page that uses it: PHP Notice: Use of undefined constant dbcontext - assumed 'dbcontext' in C:\Wiki\mw1291\extensions\Mantis\Mantis.php on line 117

PHP-version is 7.1.9

tessus commented 7 years ago

Is this the only error message? What does the PHP error log say? I'm using the extension myself, so not sure where this is coming from. I need more information. Have you set the database connection info correctly?

tessus commented 7 years ago

I've tried several edge cases, but could not reproduce this error.

The message does not even make any sense. dbcontext is not a constant, so how can it be undefined?

tessus commented 7 years ago

Unless there's a bug in PHP or mysqli for Windows.

I might have an idea. Try to change line 117 from:

if ($result = ${dbcontext}->query($dbQuery))

to

if ($result = $dbcontext->query($dbQuery))

If that works, it's not a bug in my extension. Please let me know asap.

pedwik commented 7 years ago

After changing line 117 as you suggest it works.

tessus commented 7 years ago

The good news: it works for you.

The bad news: you found a bug in PHP. Or at least an anomaly.

Also, the message you get is not an error message. It's a notice, which is even lower than a warning. Do you get any results back (the table with the Mantis tickets), or do you see an error message on the wiki page? On my Linux box, I don't get a notice and I get results.

tessus commented 6 years ago

@pedwik I've changed it in master, since the change also works on non-Windows platforms.

But out of curiosity, did you get any results back (the table with the Mantis tickets), or did you see an error message on the wiki page with the unchanged code? (The message you originally posted was just a notice after all.)

pedwik commented 6 years ago

No, I did not get any results. The only thing displayed on the wiki-page was the message.

tessus commented 6 years ago

Ok, this is really strange, because a PHP Notice should not change the intended result.

Anyway, the change is in master. What do you think? Does this warrant a new release?

pedwik commented 6 years ago

I have no idea why but with the original code I now do get a result, with the warning a the top of the page. Maybe I had a made a typo in the database name, resulting in both the warning and the missing data. What it the reason for using the brackets in this case? Could it be that PHP 7 is less "forgiving" than previous versions and raises a warning, while previous versions suppressed it?

tessus commented 6 years ago

I usually like to use brackets when there are other vars or symbols around. Technically $a$b works, but I feel it to be cleaner when writing it as ${a}${b}.

Well, I'm also using PHP 7.1.9, but on Linux. And on Linux the original code worked without the notice you got, thus I thought that the lexical parser on Windows behaved differently, which would've meant a bug in PHP. Anyway, I've removed the brackets.

If it now works for you with the old code, there's no need to tag a new release.