PHP 8.5.0 Alpha 2 available for testing

Voting

: six minus one?
(Example: nine)

The Note You're Voting On

sangala at seznam dot cz
2 years ago
Using cast and ternary operator can be unclear,
(Useful to know with: declare(strict_types = 1) ).
<?php
$num_str
="5";

$i1 = (int) isset($num_str) ? $num_str : 0;
$i2 = (int) (isset($num_str) ? $num_str : 0);
var_dump($i1);
var_dump($i2);
?>
Output:
string(1) "5"
int(5)

<< Back to user notes page

To Top