Yesterday I was programming and I made a mistake calling a variable, and the result was correct. I leave the code and I would like to know why this happens, if it is new to PHP 8 or perhaps it already existed? How does this method change?
<?php
$nombre = "Pepe";
echo "Hola {$nombre}";
// respuesta: Hola Pepe
?>
Thanks and sorry if the question is dumb.
There is no dumb question and this is not a bug, but a feature of PHP, to be able to include and interpret variables in strings using complex syntax , and in my opinion the main advantage is that it allows you to directly include array elements and properties without resorting to concatenation.
With simple variables there is not so much problem, moving on to something more complicated: Without using curly braces, you must concatenate to use array elements or object properties within a string:
Enclosing variables in braces helps you avoid concatenation:
My opinion (yes, again), it's easier to code this way and more readable.