可能重复:
参考 - 这个错误在 PHP 中意味着什么?
在下面的代码中,我创建了两个需要相同信息的函数。我正在使用这个脚本。
<?php
function get_cbMain_Query() {
define( 'Main_SERVER_ADDR', 'ip');
define( 'Main_SERVER_PORT', 25565);
define( 'Main_TIMEOUT', 1 );
// require bloginfo('template_url') . 'inc/avatars/MinecraftQuery.class.php';
require __DIR__ . '/mcQuery/MinecraftQuery.class.php';
// Display everything in browser, because some people can't look in logs for errors
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;
}
function get_cbTekkit_Query() {
define( 'Tekkit_SERVER_ADDR', 'ip');
define( 'Tekkit_SERVER_PORT', 25565);
define( 'Tekkit_TIMEOUT', 1 );
// require bloginfo('template_url') . 'inc/avatars/MinecraftQuery.class.php';
require __DIR__ . '/mcQuery/MinecraftQuery.class.php';
// Display everything in browser, because some people can't look in logs for errors
Error_Reporting( E_ALL | E_STRICT );
Ini_Set( 'display_errors', true );
$Timer = MicroTime( true );
$Query = new MinecraftQuery( );
try
{
$Query->Connect( Tekkit_SERVER_ADDR, Tekkit_SERVER_PORT, Tekkit_TIMEOUT );
}
catch( MinecraftQueryException $e )
{
$Error = $e->getMessage();
echo 'error. <br>'. $Error;
}
return $Query;
}
使用此脚本并执行以下操作来调用它(从不同的页面,此脚本包含在另一个页面中)
$cbMain = get_cbMain_Query();
$cbTekkit = get_cbTekkit_Query();
然后我得到:
Cannot redeclare class MinecraftQueryException in MinecraftQuery.class.php on line 5
我是 PHP 中的类广告对象的新手,不知道为什么我不能调用两个函数并同时使用它们。请帮忙?