English 中文(简体)
根据非对象错误调用成员函数
原标题:Call to a member function on a non-object error

我使用此代码 < a href=> 获取来自我的Minecraft服务器的信息。 它使用静态.php 文件, 但移到本地版本的 WordPress 后, 我收到以下错误 :

Fatal error: Call to a member function GetPlayers() on a non-object in C:...home.php on line 125

我敢肯定,我把所有东西都移动的正确。在125线上,是这个代码的片段:

<div class="online group container">
      <h2> Who s online </h2>
          <?php if( ( $Players = $Query->GetPlayers( ) ) !== false ): ?>
          <?php foreach( $Players as $Player ): ?>
          <div class="player">                      
            <span class="p"  title="<?php echo htmlspecialchars( $Player ); ?>" data-player="<?php echo htmlspecialchars( $Player ); ?>">☺</span>
          </div><!-- /.player -->

这是我在医生类型之前 将PHP课叫做头页.php

<?php

  define(  MQ_SERVER_ADDR ,  108.170.3.138:25643  );
  define(  MQ_SERVER_PORT , 25643 );
  define(  MQ_TIMEOUT , 1 );

  require bloginfo( template_url ) .  inc/avatars/MinecraftQuery.class.php ;

  $Timer = MicroTime( true );
  $Query = new MinecraftQuery( );

  try
  {
    $Query->Connect( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT );
  }
  catch( MinecraftQueryException $e )
  {
    $Error = $e->getMessage();
   echo  error. <br> . $Error;
  }

?>

怪怪的,因为没有在WordPress上,它工作很好, 但一旦我移动它,它就坏了。

最佳回答

创建函数以返回 Query

函数.php

function get_MQ_Query() {
  define(  MQ_SERVER_ADDR ,  108.170.3.138:25643  );
  define(  MQ_SERVER_PORT , 25643 );
  define(  MQ_TIMEOUT , 1 );

  require bloginfo( template_url ) .  inc/avatars/MinecraftQuery.class.php ;

  $Timer = MicroTime( true );
  $Query = new MinecraftQuery( );

  try
  {
    $Query->Connect( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT );
  }
  catch( MinecraftQueryException $e )
  {
    $Error = $e->getMessage();
   echo  error. <br> . $Error;
  }
  return $Query;
}

家庭 php

$Query = get_MQ_Query();
?><div class="online group container">
  <h2> Who s online </h2>
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签