2017-06-13 15 views
-1
Parse error: syntax error, unexpected '}', expecting end of file 

それが起こるには、私のremoveWalls機能間の空行とセットアップのコメントであるが、私は全く欠けているセミコロンまたは閉じられていないカッコがないことを肯定しています。誰がなぜこれが起こっているのか、それを修正する方法を知っていますか?PHP空行の構文エラー:構文エラー、予期しない「}」

$cols; 
$rows; 
$w = 20; 
$grid = new jsarray(); 
$current; 
$stack = new jsarray(); 
$height = 600; 
$width = 600; 
$cols = floor($width/$w); 
$rows = floor($height/$w); 

function index($i, $j) { 
    if ($i < 0 || $j < 0 || $i > $cols - 1 || $j > $rows - 1) { 
    return -1; 
    } 
    return $i + $j * $cols; 
} 

// Classes 
class Cell{ 
    function __construct($i,$j){ 
    $this->i = $i; 
    $this->j = $j; 
    $this->walls = new jsarray(true,true,true,true); 
    $this->visited = false; 
    } 
} 

function removeWalls($a, $b) { 
    $x = $a->i - $b->i; 
    if ($x === 1) { 
    $a->walls(3,false); 
    $b->walls(1,false); 
    } else if (x === -1) { 
    $a->walls(1,false); 
    $b->walls(3,false); 
    } 
    $y = $a->j - $b->j; 
    if ($y === 1) { 
    $a->walls(0,false); 
    $b->walls(2,false); 
    } else if (y === -1) { 
    $a->walls(2,false); 
    $b->walls(0<false); 
    } 
} 

// Setup 
for($j = 0;$j < $rows;$j++){ 
    for($i = 0;$i < $cols;$i++){ 
    $cell = new Cell($i,$j); 
    $grid->push($cell); 
    } 
} 
$current = $grid(0); 

?> 

JSarrayクラス:

<?php 
Class jsarray{ 
    function __construct(...$vals_){ 
    $this->vals = array(); 
    $this->cnt = -1; 
    if($vals_ != NULL){ 
     if($vals_ > 0 && $vals_ > 1){ 
     foreach($vals_ as $val){ 
      $this->vals[(string) $this->cnt] = $val; 
      $this->cnt++; 
     } 
     } 
    } 
    $this->length = $this->cnt+1; 
    } 
    function push(...$elements){ 
    if($elements != NULL && $elements > 0){ 
     foreach($elements as $element){ 
     $this->vals[(string) $this->cnt] = $element; 
     $this->cnt++; 
     } 
    } 
    $this->length = $this->cnt+1; 
    } 
    function pop(){ 
    if($this->length > 0){ 
     array_pop($this->vals); 
     $this->cnt--; 
    } 
    $this->length = $this->cnt+1; 
    } 
    function __invoke(int $indx,$exchange,...$vals0){ 
    if($indx != NULL && $indx > -1){ 
     return $this->vals[(string) ($indx-1)]; 
    } else if($exchange != NULL && $indx > -1) { 
     $this->vals[(string) ($indx-1)] = $exchange; 
    } else if($vals0 != NULL){ 
     $this->vals = array(); 
     $this->cnt = -1; 
     $this->cnt = -1; 
     if($vals_ > 0 && $vals_ > 1){ 
     foreach($vals_ as $val){ 
      $this->vals[(string) $this->cnt] = $val; 
      $this->cnt++; 
     } 
     } 
    } 
    } 
} 
    function concat(self ...$arrays){ 
    if($arrays > 0 && $arrays != NULL){ 
     $finalarr = $this; 
     foreach($arrays as $array){ 
     $finalarr->vals = array_merge_recursive($finalarr->vals,$array->vals); 
     } 
     $finalarr->length = count($finalarr->vals); 
     $finalarr->cnt = $finalarr->length-1; 
     return $finalarr; 
    } 
    } 
    function reverse(){ 
    $this->vals = array_reverse($this->vals); 
    } 
} 
// one $ for every line of this file 
?> 

誰もが興味を持っている場合は、私はPHPにいくつかのJSを翻訳しようとしていたとJS、PHPは、このページに両方とも:$サインオン欠落https://github.com/AlexDvorak/PHP-Coding-Train

+1

'$ B->壁(0 <偽);'これは、それがすることになってどのようにでしょうか? –

+0

残っていた閉鎖}がありませんでした。他の回答で以前に指摘された問題と同様に、 – theman26

答えて

1

でなければなりません。 $記号が見つからないと、無効な引数が以下のように変更し :

function removeWalls($a, $b) { 
    $x = $a->i - $b->i; 
    if ($x === 1) { 
    $a->walls(3,false); 
    $b->walls(1,false); 
    } else if ($x === -1) { //<-------------Mark here 
    $a->walls(1,false); 
    $b->walls(3,false); 
    } 
    $y = $a->j - $b->j; 
    if ($y === 1) { 
    $a->walls(0,false); 
    $b->walls(2,false); 
    } else if ($y === -1) { //<-------------Mark here 
    $a->walls(2,false); 
    $b->walls(0,false); //<-------------Mark here 
    } 
} 
+0

前と同じエラー – theman26

2

} else if (y === -1) {は、} else if ($y === -1) {である必要があります。

また、この$b->walls(0<false);はおそらくあなたがremoveWalls機能に多少の誤差があります$b->walls(0, false);

+0

前と同じエラー – theman26

関連する問題