Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does mean if (\false) (yes, with backslash) in PHP?

Tags:

namespaces

php

This morning, I've been notified that a new Twig_Extensions release is available! Yay!

Before integrating it to twigfiddle, I wanted to see changes. This is mainly adding support to namespaces using class_alias function, and then add PSR-4 correspoding classes that just include the legacy one.

But each new (namespaced) classes are implemented like this:

<?php

namespace Twig\Extensions;

require __DIR__.'/../lib/Twig/Extensions/Extension/Text.php';

if (\false) {
    class TextExtension extends \Twig_Extensions_Extension_Text
    {
    }
}

What does this notation mean?

like image 202
Alain Tiemblo Avatar asked May 24 '17 08:05

Alain Tiemblo


1 Answers

It means it's using the false defined in the global namespace..

After a bit of research it turns out the rest of this answer is nonesense... I could swear you were able to do this in PHP at one point in time.

I think this is get around the situation where

<?php
namespace whywouldyoudothis;

false = true;
?>

I have never ever seen anyone code for this but that's what springs to mind.

like image 94
Dale Avatar answered Jan 04 '23 00:01

Dale