Domanda

I have another problem.

Im getting an internal server error when I try to get data from the following php class:

<?php
/**
 * Created by JetBrains PhpStorm.
 * User: -Ryuk-
 * Date: 21/11/12
 * Time: 17:08
 * To change this template use File | Settings | File Templates.
  */
class game
{
    private $_serverStatus = "Online";
    private $_numOnline = "32";
    private $_maxPlayers = "50";
    private $_messageOfTheDay = "Welcome to game!";
    private $_Players = "Falcubar2011;Zacardor;";

public function GetStatus()
{
    return this::$_serverStatus;
}

public function GetNumOnline()
{
    return this::$_numOnline;
}

public function MaxPlayers()
{
    return this::$_maxPlayers;
}

public function GetMOTD()
{
    return this::$_messageOfTheDay;
}

public function GetPlayers()
{
    return this::$_Players;
}

public function GetServiceColour()
{
    if(this::GetStatus() != "Online")
        return "#FF0000";
    else
        return "#008000";
}
}

Im trying to call it like this(in index.php) I stripped this down so you don't get all the junk.

$mc = new game();

  <div id="Stats">
        <div id=roundedbox>
            <h1>Info</h1>
            <p>
            <p><strong>IP:</strong> play.game.com</p>
            <br>

            <p>Slots: <?php print $mc->GetNumOnline(); ?> / <?php print $mc->MaxPlayers(); ?></p>
            <br>
            <p>Status: <?php print $mc->GetStatus(); ?></p>
            <br>
            <p>MOTD: <?php print $mc->GetMOTD(); ?></p>
            </div>
    </div>

Anyone know how to fix this problem im having?

È stato utile?

Soluzione

Your syntax around this is completely wrong. Instead of

return this::$_serverStatus;

You should be using

return $this->_serverStatus;

Similarly, your internal call to GetStatus() should be

if ($this->GetStatus() != 'Online') {
    // ...

I recommend you start reading here - http://php.net/manual/en/language.oop5.basic.php

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top