PHP typing practice: read mixed syntax

When PHP puts a property, an array key, and a default on the same line, read the expression from left to right before typing it. This guide shows how to tell ->, =>, and ?? apart in a small ledger, then copy the same pattern without a prompt.

Language practice guide
In this guide, you’ll practice

Follow the receiver → distinguish the arrows → copy the line from a cue

01 Read object access and array keys

Start at $ledger, then follow the property, key and fallback. The same array appears in two forms here: once as a literal that creates a pair, and once as a lookup that reads it.

ledger.phpReference
class Ledger {
    public array $totals = [];
}

$ledger = new Ledger();
$ledger->totals = ['books' => 0];
$amount = $ledger->totals['books'] ?? 5;

02 Copy the ledger line from a cue

$ledger->totals
The object is on the left. Type -> and then totals, without a $ before this literal property name.
'books' => 0
Here => pairs a key with a value inside the array literal. It does not read the key.
['books'] ?? 5
The square brackets read the key. The fallback applies if the entry is missing or null; an existing 0 stays 0.

Cover the final line. In an editor, type an assignment to $amount that reads the books key from the ledger’s totals property and defaults to 5. Then compare the exact characters with the source.

Reveal the reference line and checks

Expanded recall answer

$amount = $ledger->totals['books'] ?? 5;

Check the receiver $, the -> arrow, single quotes around the key, both question marks and the final semicolon. books returns 0; pens returns 5. PHP lint and both cases passed.

03 Practice with PHP code

Start in your editor, then carry one pattern into the timed test. The article example and the test passage are separate.

  1. 01
    Read the receiver and key

    Read the final ledger line from the receiver through ->, brackets and ??. Compare it with the => pair in the literal.

  2. 02
    Copy the line from a cue

    Use the cue above without looking at the last line. Reveal the reference and compare the characters before running your copy.

  3. 03
    Try the same transition in a PHP test

    Notice the handoff from a property to an array key in the passage. The passage may not contain the same code.

Try the PHP typing test

Look for the same typing pattern in the displayed passage.

Start PHP typing test

04 Review the copy and the result

Change only books to pens in your copy. Predict 0 for books and 5 for the missing pens key. If the output is right but the reference differs, record the source mismatch separately.

In the timed test, record the language, duration, CPM, accuracy and one transition to revisit. Compare runs of similar duration and mode; different snippets can change the result.

Understand CPM and WPM for code →

05 Keep learning