Access to a specific variable inside <<< HTML in php

I am trying to understand how to use a specific variable when used <<<HTMLin php. This is an example of what I want to achieve:

<?php
define('TEST','This is a test');
echo <<<HTML
Defined: {TEST}
HTML;
?>

What is the appropriate way to get a specific β€œTEST” inside <<<HTML?

Edit:
I did a little test to check which of the methods is the fastest. For my test, I used 20 variables inside the heredoc. Here's what happened with the different methods (in seconds):
Accessing a specific variable inside <<< HTML in php seems to be the slowest way to do this - 0.00216103.
Access to a specific variable inside <<lt; HTML in php is faster - 0.00073290.
Access to a specific variable inside <<lt; HTML in php runs even faster - 0.00052595.
Access to a specific variable inside <<lt; HTML in php is the fastest - 0.00011110.

Hope this helps someone else :)

+5
5

, , ...

define('TEST','This is a test');

var $defined = TEST;

echo <<<HTML
Defined: {$defined}
HTML;

, , , .

+10

, php: http://www.php.net/manual/en/function.define.php#100449

, .

<?php
define('TEST','This is a test');

$cst = 'cst';
function cst($constant){
    return $constant;
}

echo <<<HTML
Defined: {$cst(TEST)}
HTML;

CONSTANTS , , .

+5

, :

class DefineAccessor {
    function __get($name) {
        if (defined($name))
            return eval('return ' . $name . ';');
    }
}

, heredoc:

$defines = new DefineAccessor;

:

echo <<<HTML
Defined: $defines->TEST
HTML;
+4

. .

+3

All Articles