PHP overwrite of built-in constants (true is false)

Here is a scary thing I picked up on Reddit PHP:

<?php
use const true as false;
if (false) {
    echo "uh-oh";
}

Until PHP 5.6 this was throwing a parse error, but from then on – it’s just fine.  Scary, right?

The comments on the Reddit thread are quite helpful.  Technically, this is not overwriting (shadowing?) since the original constant is still available:

<?php
use const true as false;
if (\false) {
    echo "uh-oh";
}

If you are a fan of nightmares, there is also this link, which will shake your religious beliefs …

Leave a Comment