Testing and assertions
Compare an observable result against an explicit expectation and include boundary cases.
CKTIS / PHP
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Compare an observable result against an explicit expectation and include boundary cases.
DateTimeImmutable returns a new object when modified.
Use an enum to close the set of allowed cases and a trait to share methods between types.
An explicit cast applies conversion rules for the target type.
Type declarations check arguments, return values and properties.
A dollar sign introduces a case-sensitive variable name.
The zend.assertions directive controls compilation and execution of assert expressions.
FILTER_VALIDATE_EMAIL selects PHP’s email syntax validator.
INF is the positive floating-point infinity, and negation produces negative infinity.
The pair PHP_INT_MAX / PHP_INT_MIN names the largest and smallest native signed integers, with limits dependent on the build’s integer width.
PASSWORD_BCRYPT explicitly selects bcrypt for password_hash.
PHP_EOL is the platform-specific line ending of the PHP runtime: LF on Unix-like systems and CRLF on Windows.
STR_PAD_LEFT selects left padding in str_pad to reach a target byte length.
With `use (&$carry)`, a closure and its defining scope can read and update the same variable. Without `&`, the closure captures the value at creation time.
`use (&$MAP)` lets an anonymous function read and update the current state of `$MAP` from the scope where the function was defined.
In PHP, `use (&$vat)` lets a closure share a variable with the scope where the closure was created. Without `&`, the closure keeps the scalar value from creation time.
Read the text of a caught exception, distinguish it from the code and stack trace, and decide what belongs in a log versus a user-facing response.
Use `&$p` to update array elements directly in a `foreach` loop. Call `unset($p)` afterward so a later assignment does not accidentally overwrite an array element.
Use `&$row` to update array elements in place, then call `unset($row)` after the loop to detach the reference to the last visited element.
Put `&` before the value variable to edit array elements in place. Call `unset($p)` after the loop so later assignments cannot change the last visited element through that variable.
Use `&$value` to update array elements in place, and learn why `unset($value)` prevents a later loop from accidentally overwriting the last element.
Read a generator’s final result after it completes normally. The value from `return` is separate from the items produced by `yield`.
Implement `getIterator()` to control which keys and values `foreach` reads from an object. The method supplies a `Traversable` object, not an array.
Read the value at an iterator’s current position without advancing it. Use `valid()` to check the position so that `null` and `false` are not mistaken for the end of iteration.