note 100449 deleted from function.define by cmb

From: Date: Sun, 06 Oct 2019 07:57:00 +0000
Subject: note 100449 deleted from function.define by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212487@lists.php.net to get a copy of this message
Note Submitter: toph at farmer corp dot c om ---- Hi, Here is a trick to use constants within the heredoc notation. <?php define('MY_CONSTANT','foo bar') $cst = 'cst'; function cst($constant){ return $constant; } $string = <<<EOF My constante MY_CONSTANT : {$cst(MY_CONSTANT)} ... EOF; echo $string; ?> That will echo : My constante MY_CONSTANT : foo bar ... As you can use function within the heredoc notation the idea is to use a fonction to return the value of the constant. Be carefull, to use a function, it's necessary to declare the name of the function as a variable and to use that varaible during the "call" of the constant. It works for me and doesn't seem too messy. Hope that will help.

« previous php.notes (#212487) next »