2017-06-13 111 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