2017-06-13 68 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 
?> 

如果有人有興趣,我想翻譯一些JS到PHP和JS和PHP這個頁面上都是:https://github.com/AlexDvorak/PHP-Coding-Train

+1

'$ B->牆壁(0 <假);'這是怎麼應該是什麼? –

+0

有一個錯誤的關閉}沒有{一個以及在前面指出的問題在其他答案 – theman26

回答

1

您在removeWalls功能有一定的誤差。缺少$標誌和無效的參數 改變它象下面這樣:

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);也許應該$b->walls(0, false);

+0

與以前相同的錯誤 – theman26