php version guide
PHP 7.3 Changes
PHP 7.3 is a smaller application-facing release. Flexible heredoc syntax, trailing commas in function calls, array_key_first(), array_key_last(), and is_countable() are useful maintenance improvements.
Changes Worth Recognising
- Use
array_key_first()andarray_key_last()instead of moving an array pointer for simple key lookup. is_countable()helps when maintaining mixed legacy inputs.- Trailing commas reduce diff noise in multiline calls.
- Flexible heredoc indentation makes embedded text easier to align.
Representative Code
PHP example
<?php
$totals = ['draft' => 4, 'published' => 12];
echo array_key_first($totals) . PHP_EOL;
echo array_key_last($totals) . PHP_EOL;
// Prints:
// draft
// published
Upgrade Review
- Do not confuse first or last insertion order with minimum or maximum value.
- Use a clear domain type instead of
is_countable()when you control the API. - Run formatting tools after adopting multiline trailing commas.
These additions are small, but they replace several awkward patterns that often survive in long-lived codebases.
Practice
Replace Pointer-Based Lookup
Replace a legacy reset() plus key() sequence with array_key_first(). Explain what happens for an empty array.
Show solution
array_key_first($items) returns the first key without changing the internal array pointer. It returns null for an empty array.