I can confirm the last post. This method does not work when part of a function, which is a big problem when integrating into some existing sites.
This works:
PHP Code:
$cwd = getcwd();
chdir("/mypath");
include("/mypath/global.php");
include("/mypath/includes/class_bbcode.php");
$bb_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
chdir($cwd);
function bb_convert_works($bb_parser, $text){
$parsed_text = $bb_parser->do_parse($text);
return $parsed_text;
}
$text = "[url=http://www.google.com][b]Google[/b][/url]";
echo bb_convert_works($bb_parser, $text);
This does NOT work:
PHP Code:
function bb_convert_doesnt_work($text){
$cwd = getcwd();
chdir("/mypath");
include("/mypath/global.php");
include("/mypath/includes/class_bbcode.php");
$bb_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
chdir($cwd);
$parsed_text = $bb_parser->do_parse($text);
return $parsed_text;
}
$text = "[url=http://www.google.com][b]Google[/b][/url]";
echo bb_convert_doesnt_work($text);
The errors I get when I try the second code are:
Quote:
Warning: array_keys() [function.array-keys]: The first argument should be an array in [path]/includes/functions.php on line 4227
Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 4227
Fatal error: Call to a member function query_read_slave() on a non-object in /mypath/includes/functions.php on line 3189
|
I have plenty of experience in PHP, but I haven't encountered a problem like this before. I really would prefer to not have to hack this together by hard coding the conversion code everywhere I need it. Does anyone have any ideas on why it breaks when within a function?