When writing code in the global scope, I often have a problem where I’m overwriting a variable. This happens even more often when I work on code of somebody else. Usualy has the variable which does the overwriting is usualy just a temporary variable.

It’s difficult to choose a general name for all temporary, since you want a short name, but others might have used it for other purposes. However with ${’…’}, you can use any string as variable name, even an empty string of a string with spaces. Numbers get automatically cast to a string. So I nice way of solving the problem could be:

${0} = fwrite($fh, 'Test');
if (!${0}) throw new Exception("Writing the file has failed");
 
if ((${0} = pathinfo('/var/www/index.html')) && ${0}['extension'] === 'html')
  echo "Yes boys and girls";
}