Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cast But Not A Cast

<?php

$string = '123';
$integer = 0 + $string;
$integer = $string - 0;
$integer = 1 * $string;
$integer = $string / 1;
$integer = $string ** 1;
$integer = + $string;
$integer = - - $string;

echo '123' ** 0;


?>

One frequent way to convert a string to an integer is to + 0 it. And, similarly, a frequent way to convert an integer into a string is to . '', aka concatenate the empty string.

The operators often proceed with a silent cast before running the actual operation. Hence, when using the neutral element of that operator, only the cast remains.

Note also that the silent cast is actually not silent when there is an issue with the conversion, while an actual cast silences these warnings: it is always better to use the cast.

Here are the other cases.

See Also

PHP Error Messages

PHP Features

Last updated: 10 September 2026