2017-10-11 23 views
2

當我重新安裝我的XAMPP和運行我laravel項目,我得到這個錯誤 FatalErrorExceptionFatalErrorException語法錯誤,意外的':',期待';'或「{」在PermissionRegistrar.php

語法錯誤,意想不到的「:」,希望「;」或 '{' 在 PermissionRegistrar.php(線33) 我的代碼是

public function __construct(Gate $gate, Repository $cache, Log $logger) 
{ 
    $this->gate = $gate; 
    $this->cache = $cache; 
    $this->logger = $logger; 
} 
public function registerPermissions(): bool 
{ 
    try { 
     $this->getPermissions()->map(function (Permission $permission) { 
    $this->gate->define($permission->name, function ($user) use($permission) 
{ 
       return $user->hasPermissionTo($permission); 
      }); 
     }); 
     return true; 
    } catch (Exception $exception) { 
     if ($this->shouldLogException()) { 
      $this->logger->alert(
"Could not register permissions because {$exceptiongetMessage()}".PHP_EOL. 
       $exception->getTraceAsString() 
      ); 
     } 
     return false; 
    } 
} 
+0

哪裏是你的代碼?錯誤很明顯。你爲什麼不修復它? – Hassaan

+0

@saranya:1)請檢查您的循環是否正確關閉。 2)請驗證是否缺少任何半色調 – Abhijit

+0

分享'PermissionRegistrar.php(第33行)'和上面一行? – C2486

回答

0

Return type declaration support is added to php 7。所以從

public function registerPermissions(): bool 

刪除: bool(因爲你是目前PHP 31年6月5日),以

public function registerPermissions() 
+0

我想這是一個PHP版本問題是不是? – usertest

+0

是的,它的PHP版本問題,這就是爲什麼我問你目前的版本。您使用的語法由PHP 7支持 –

+0

是的,我已經更改了我的版本,現在可以使用,謝謝 – usertest

相關問題