-2

私が持っているエラーは ですがunexpected T_STRING, expecting '(' on line 22、欠落しているものはありませんでし(た。

ここで何が起こっているのか、誰か説明してもらえますか? 22行目より前に何か見逃しましたか?

これが私のコードです:

<?php

class Room { 
  protected $description = "";
  protected $name = "";
  protected $rooms = array(
   "ne" => NULL,
   "n" => NULL,
   "nw" => NULL,
   "e" => NULL,
   "c" => NULL,
   "w" => NULL,
   "se" => NULL,
   "s" => NULL,
   "sw" => NULL 
   );

  public function __construct ($n = "", $desc = "") { 
    $this->description = $desc;
    $this->name = $n;
  } 

  public function get Description () {
    return $this->description; 
  }

  public function get Name () {
    return $this->name; 
  }

  public function set Room ($direction = "c", $room) {
    $this->rooms[$direction] = $room; return True; 
  }

  public function getNewRoom ($direction = "") {
    return $this->rooms[$direction]; 
  } 
}


$start Room = new Room ("First Room", "A small room. There is a door to the north.");
$second Room = new Room ("Second Room", "A short hallway that ends in a dead end. There is a door to the south.");
$start Room->set Room("n", $second Room);
$second Room->set Room("s", $first Room);
$current Room = $start Room;

$play = True; 

while ($play) {
  print $current Room->get Name();
  print $current Room->get Description();

  $input = readline("(Enter your command. Type QUIT to quit.) >");

  if ($input == "QUIT") {
    $play = False; 
  } else { 
    if ($input == 'nw' || 
        $input == 'n' || 
        $input == 'né' || 
        $input == 'e' || 
        $input == 'e' || 
        $input == 'e' || 
        $input == 'e' || 
        $input == 'e' || 
        $input == 'e') 
    { 
      $current Room = $current Room->getNewRoom($input); 
    }
  } 

}

?>
4

1 に答える 1

10

多くのメソッドの名前にはスペースが含まれています。

public function get Description () {
public function get Name () {
public function set Room ($direction = "c", $room) {

これらは許可されていません。1語の名前を使用する必要があります。

public function getDescription () { // For example

次に、同じように呼び出します。

print $currentRoom->getDescription();

同じことが変数にも当てはまります。

$current Room = $start Room; // Not allowed
$currentRoom = $startRoom; // Good!
于 2012-09-17T21:02:33.973 に答える