Type conversion
An explicit cast applies conversion rules for the target type.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
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.
Read the current element’s key without advancing the iterator, and see how PHP assigns that key in a `foreach` loop.
`Iterator::next()` advances an iterator by one step without returning the element. When iterating manually, check `valid()` before reading the value with `current()`.
`foreach` calls `Iterator::rewind()` before its first `valid()` check. Whether that call positions the iterator at its start depends on the implementation.