PDA

View Full Version : Call to undefined function fetch_phrase


dwooding
03-07-2013, 03:57 AM
I'm using a custom php script to create users in VBulletin 4.x. The scripts calls core VBulletin files, ex - require_once(CWD . '/includes/class_core.php');.

Unfortunately, when a username already exists, the script throws a fatal error:

Fatal error: Call to undefined function fetch_phrase() in /home/xxxxx/public_html/members/includes/functions.php on line 4030

Line 4030 in the functions looks like this:


// API only needs error phrase name and args.
if (defined('VB_API') AND VB_API === true)
{
return $args;
}

$args[0] = fetch_phrase($args[0], 'error', '', false); // line 4030
if (sizeof($args) > 1)
{
return call_user_func_array('construct_phrase', $args);
}
else
{
return $args[0];
}


Of course, the fetch_phrase function does exist, in /includes/functions_misc.php.

Within functions.php, the only time I see the fetch_phrase function get loaded is within the print_standard_redirect function


if (!function_exists('fetch_phrase'))
{
require_once(DIR . '/includes/functions_misc.php');
}


My take after looking around the functions.php file is that when an error occurs, there is an attempt to redirect ????

Given what I have shown, any idea on why I'm getting the "Call to ?" error message.

I'm using vBulletin 4.2.0 Patch Level 2.

Thanks.

Dave

Other related posts:

http://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-4-questions-problems-and-troubleshooting/396256-php-error-call-to-undefined-function-fetch-phrase-in-functions-php-line-3518?

https://vborg.vbsupport.ru/showthread.php?t=269898&highlight=fetch_phrase

kh99
03-07-2013, 12:23 PM
It seems strange that someone else was getting that error on the same line, but I don't understand why a missing phrase would be the problem.

I have the code for version 4.2.0PL2, and I have this code at line 4008:
if (!function_exists('fetch_phrase') AND !VB_API)
{
require_once(DIR . '/includes/functions_misc.php');
}


It seems to me that the only way that could not load is if your script was defining VB_API as something other than 'true' (or if fetch_phrase was already loaded, of course).

In any case, if it were me, I'd put in some debug statements. For example, I'd probably put a die() right before the require_once and see if it's getting there at all. Or maybe comment out the 'if' line and the closing } and so it's always included, and see if that fixes it. (Of course those changes are just temporary, you'd remove them after you see what happens).

ForumsMods
03-07-2013, 01:35 PM
You need to add this to your code:

define('VB_API', false);

kh99
03-07-2013, 01:39 PM
You need to add this to your code:

define('VB_API', false);


Yeah, that makes sense. That's done in init.php, but it could be that his script isn't including that.

ForumsMods
03-07-2013, 02:13 PM
Yes.
This will always return false: !VB_API, because VB_API is not defined.
It is defined in includes/init.php which is included in includes/class_bootstrap.php and this is included in global.php.
And because he is not including any of the above files, VB_API is not defined.

kh99
03-07-2013, 02:21 PM
And because he is not including any of the above files, VB_API is not defined.

Oh right - I missed the first line where it said he was including class_core.php, and assumed he must be including global.php.

dwooding
03-08-2013, 02:05 AM
You're great! Works perfect. Thanks. Dave