PHP 8.5.0 Beta 1 available for testing

Voting

: eight minus one?
(Example: nine)

The Note You're Voting On

ssj dot narutovash at gmail dot com
17 years ago
It's come to my attention that you cannot use a static member in an HEREDOC string. The following code

class A
{
public static $BLAH = "user";

function __construct()
{
echo <<<EOD
<h1>Hello {self::$BLAH}</h1>
EOD;
}
}

$blah = new A();

produces this in the source code:

<h1>Hello {self::}</h1>

Solution:

before using a static member, store it in a local variable, like so:

class B
{
public static $BLAH = "user";

function __construct()
{
$blah = self::$BLAH;
echo <<<EOD
<h1>Hello {$blah}</h1>
EOD;
}
}

and the output's source code will be:

<h1>Hello user</h1>

<< Back to user notes page

To Top