Recently downloaded some code for a minor open-source project related to a small webgame I play. Trying to access it fails and spits out an error message of:
PHP Fatal error: Call to undefined function v() in /Applications/MAMP/htdocs/infocenter/modules/security_mod.php on line 7
After searching, I found that the function v() is defined in a file called “system.php” which is required by a file which is required by a file which is required by the “security_mod.php” file that the error occurs in. No errors occur with any of the require calls (and they’re all ‘require_once’, not an ‘include’).
This is the whole of the system.php file:
<?php
function v($a, $i)
{
return isset($a[$i]) ? $a[$i] : null;
}
?>
This is the function in ‘security_mod.php’ that throws the error (also including the require calls):
<?php
require_once("settings_mod.php");
require_once("account_mod.php");//this file requires base_mod.php, which requires system.php
class SecurityMod {
public static function checkLogin() {
$name = v($_REQUEST, "acc");//this is the line that causes the error
$password = v($_REQUEST, "pwd");
if (!isset($name) || !isset($password)) {
return null;
}
$acc = AccountMod::getAccount($name);
if (SettingsMod::USE_ENCRYPTED_PASSWORDS) {
if (is_null($acc) || $acc->getPassword() != md5($password)) {
return null;
} else
return $acc;
} else {
if (is_null($acc) || $acc->getPassword() != $password) {
return null;
} else
return $acc;
}
}
?>
I did a little testing, and found out that I can access variables and functions in some of the other required files. All of those are in classes, though, unlike v(). Would that be the reason?
EDIT to clarify how ‘system.php’ is required:
‘security_mod.php’ has these two require_once calls at the beginning of the file:
require_once("settings_mod.php");
require_once("account_mod.php");
‘settings_mod.php’ is a file containing constants used through the program, and includes no files.
‘account_mod.php’ has these two require_once calls:
require_once("base_mod.php");
require_once("account.php");
‘account.php’ has a pair of include_once calls that include inconsequential and unrelated files.
‘base_mod.php’ is the file with the ultimate requirement for ‘system.php’:
require_once("system.php");
require_once("settings_mod.php");
Found the issue: the
System.phpfile being successfully included wasn’t the same as the one in the downloaded code. Sincebase_mod.phponly provided a filename, not a path, PHP first checked in the directory specified by myinclude_path, which turns out to contain a file namedSystem.php. Since my filesystem is case-insensitive, that was judged to be the same assystem.php, and therefore got included instead.