PHP – Garbage Code and Bad Variables

Since Variables in PHP do not need to be declared you can run into issues such as trying to add a String to an Int. You also may have issues if you misspell a variable.

 

<?php

$string = “Hello World”;
$int = 1;
$float = 2.2;
$garbage = $FLOAT + $int;
$garbage2 = $string + $int;

print “<h1>String</h1>”;
print $string;
print “<h1>Int</h1>”;
print $int;
print “<h1>Float</h1>”;
print $float;
print “<h1>Garbage (Capitalization Error)</h1>”;
print $garbage;
print “<h1>Garbage2 (Adding a String)</h1>”;
print $garbage2;
?>

 

Be the first to comment

Leave a Reply