在头版。php我有以下代码:
<span class="amountOnline">
Online:
<?php echo $cbMain->GetInfo()[\'Players\'] . \'/\' . $cbMain->GetInfo()[\'MaxPlayers\']; ?>
</span>
这是函数中的函数。调用的php
this script.它工作得很好。
但一旦我把代码从front-page.php
到header.php
, 我收到以下错误:\'
Notice: Undefined variable: cbMain in C:\\Users\\...\\header.php on line 102
Fatal error: Call to a member function GetInfo() on a non-object in C:\\Users\\...\\header.php on line 102
在函数中。php,我有这个函数,例如:
function get_cbMain_Query() {
define( \'Main_SERVER_ADDR\', \'0.0.0.0\');
define( \'Main_SERVER_PORT\', 25565);
define( \'Main_TIMEOUT\', 1 );
// require bloginfo(\'template_url\') . \'inc/avatars/MinecraftQuery.class.php\';
require_once __DIR__ . \'/includes/mcQuery/MinecraftQuery.class.php\';
Error_Reporting( E_ALL | E_STRICT );
Ini_Set( \'display_errors\', true );
$Timer = MicroTime( true );
$Query = new MinecraftQuery( );
try
{
$Query->Connect( Main_SERVER_ADDR, Main_SERVER_PORT, Main_TIMEOUT );
}
catch( MinecraftQueryException $e )
{
// $Error = $e->getMessage();
// echo \'error. <br>\'. $Error;
}
return $Query;
}
那么
$cbMain = get_cbMain_Query();
所以我可以在静态首页中使用函数。php文件,但一旦我将此脚本移到页眉。php,它不工作,并给出了一个错误。如何修复此问题?