Get all documents in a collection in PHP, Firebase

In the Cloud Firestore documentation:
https://firebase.google.com/docs/firestore/query-data/get-data

I have copied this example:

$citiesRef = $db->collection('cities');
$citiesRef->document('SF')->set((
    'name' => 'San Francisco',
    'state' => 'CA',
    'country' => 'USA',
    'capital' => false,
    'population' => 860000
));
$citiesRef->document('LA')->set((
    'name' => 'Los Angeles',
    'state' => 'CA',
    'country' => 'USA',
    'capital' => false,
    'population' => 3900000
));
$citiesRef->document('DC')->set((
    'name' => 'Washington D.C.',
    'state' => null,
    'country' => 'USA',
    'capital' => true,
    'population' => 680000
));
$citiesRef->document('TOK')->set((
    'name' => 'Tokyo',
    'state' => null,
    'country' => 'Japan',
    'capital' => true,
    'population' => 9000000
));
$citiesRef->document('BJ')->set((
    'name' => 'Beijing',
    'state' => null,
    'country' => 'China',
    'capital' => true,
    'population' => 21500000
));
printf('Added example cities data to the cities collection.' . PHP_EOL);

And the request :

$citiesRef = $db->collection('cities');
$query = $citiesRef->where('capital', '=', true);
$documents = $query->documents();
foreach ($documents as $document) {
    if ($document->exists()) {
        printf('Document data for document %s:' . PHP_EOL, $document->id());
        print_r($document->data());
        printf(PHP_EOL);
    } else {
        printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
    }
}

I can’t go to the else block.
If I change where('capital', '=', true) to where('capital', '=', 'test'), the condition should be false and I enter the else block because the documents no ‘does not exist.

But I have a blank page.
can someone explain to me?
Thank you.