'"Unexpected 'StringLiteral'
I have no idea why has this error occurred.....Can Anyone help me? I try to make a connection to the firestore.
<br/>
<?php
require_once 'vendor/autoload.php';
use Google\Cloud\Firestore\FirestoreClient;
class GFireStore
{
protected $db;
protected $name;
public function __construct(string $collection)
{
$this->db = new FirestoreClient([
'projectId' -> 'final-fyp-project-1c86c'
]);
$this->name = $collection;
}
public function getDocument(string $name){
try{
if($this->db.collection($this->name)->document($name)->snapshot()->exists()){
return $this -> db.collection($this->name)->document($name)->snapshot()->data();
}else{
throw new Exception("Document are not exists");
}
}catch(Exception $exception){
return $exception ->getMessage();
}
}
}
Solution 1:[1]
The proper syntax for PHP associative arrays is 'projectId' => 'final-fyp-project-1c86c'. The -> syntax is reserved for accessing object's properties and methods.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Grzegorz Pietrzak |

