In PHP 7.1, how can you cast a specific type for a variable and how does it differ from earlier versions?

In PHP 7.1 and later versions, you can use the `declare` statement to specify strict typing for a variable, ensuring that it must be of a specific data type. This differs from earlier versions where strict typing was not enforced by default, allowing variables to be dynamically typed. By casting a specific type for a variable in PHP 7.1, you can prevent unexpected type-related errors and improve code reliability.

<?php
declare(strict_types=1);

// Cast a variable to a specific type
$stringVar = (string) "123";

// This will throw a TypeError as the variable is expected to be a string
$intVar = (int) $stringVar;
?>