Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with getVersionData() #16655

Open
BobRay opened this issue Dec 4, 2024 · 0 comments
Open

Issue with getVersionData() #16655

BobRay opened this issue Dec 4, 2024 · 0 comments
Labels
bug The issue in the code or project, which should be addressed.

Comments

@BobRay
Copy link
Contributor

BobRay commented Dec 4, 2024

Bug report

Summary

Because $modx->getVersionData() uses include_once() and returns that result, it will return true if called more than once. This doesn't happen in normal MODX operations because the include only executes if $modx->version === null.

In unit, integration, and acceptance tests, there are cases where MODX is instantiated, and the version is checked in more than one test. Because the tests are run in the same PHP scope, it appears that PHP knows the file was included, but $modx->version is null.

In those cases, the include returns true, so getVersionData()['version'] becomes 1['version'], and throws a PHP error (which goes unreported because of the @ sign). This causes problems that are very difficult to track down.

A workaround is to include the version file directly without calling the function, but I can't think of any reason include_once couldn't be replaced by just include. In normal MODX operation, the include will only happen once anyway, and including the version file a second time is completely harmless. It will return the same value each time, and the difference between the time to include the file and the time to check to see if it's already been included is probably trivial.

Step to reproduce

$x = include_once 'C:\xampp\htdocs\addons\core\docs\version.inc.php';
echo "\nX: " . $x['version'];

$y = include_once 'C:\xampp\htdocs\addons\core\docs\version.inc.php';
echo "\n\nY";
var_dump($y);

Observed behavior

Result:

X: 2 (or 3)
Y: (bool) true

Expected behavior

Return values should be the same

@BobRay BobRay added the bug The issue in the code or project, which should be addressed. label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue in the code or project, which should be addressed.
Projects
None yet
Development

No branches or pull requests

1 participant