Unquoted text as a variable value in PHP

<?php
$animal = CAT; // outputs Notice: Use of undefined constant cat - assumed 'cat'

echo $animal; // ouputs CAT

define('CAT', '4 legs');

$animal = CAT;

echo $animal; // outputs 4 legs

/* conclusion: undefined constant name and unquoted string value will be converted into string automatically */
?>

Comments

Popular posts from this blog

Timus 1209. 1, 10, 100, 1000... accepted solution in C

Timus Problem 1086. Cryptography Accepted Solution in C

Timus 1083. Factorials!!! Accepted Solution in C