Why doesn't this work? PHP: use pocketmine\utils\TextFormat;$color = "green";var_dump(constant("TextFormat::" . strtoupper($color))); Error: Code: ClassNotFoundException: "Class TextFormat not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 144
Try putting the full class path of TextFormat. Instead of putting just "TextFormat", try putting "pocketmine\utils\TextFormat", and see if you still get that error.
Because the declaration of classes, in this problem using "Namespaces" fixes the problem, as the processor will gather it as a "class reference" instead of a simple string
If you want to use imports, try this: PHP: constant(TextFormat::class . "::BLUE"); Note that `use` is something that is run at compile time, replacing all type references of that type in your code into the full class reference. "TextFormat" is a string. According to php.net, all use statements are interpreted at compile time, where the compiler would not know that you are trying to use TextFormat as a class reference. Or do you want your messages sent to a player "I am a message with the word TextFormat inside" get changed for no reason at all? In PHP string literals, direct usage of backslashes has to be escaped. So you have to use "\\" instead. Although it currently works without errors, it is wrong programming practice (for instance, if you use "pocketmine\nbt", it will convert "\n" into a linefeed). Furthermore, according to PHP 7 Backwards-Incompatible Changes: This means that using \u incorrectly will result in an error, which applies directly to you. PHP 7 or not, it is wrong to try to use \ as a backslash in a string literal anyway. If you use single quotes, you can use backslashes without escaping, as long as the backslash isn't followed by a ' directly.