note 80162 added to language.oop5.static

From: Date: Wed, 02 Jan 2008 04:48:39 +0000
Subject: note 80162 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-134651@lists.php.net to get a copy of this message
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> ---- Server IP: 66.207.199.35 Probable Submitter: 65.92.136.74 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.static.php Edit -- https://master.php.net/note/edit/80162 Del: integrated -- https://master.php.net/note/delete/80162/integrated Del: useless -- https://master.php.net/note/delete/80162/useless Del: bad code -- https://master.php.net/note/delete/80162/bad+code Del: spam -- https://master.php.net/note/delete/80162/spam Del: non-english -- https://master.php.net/note/delete/80162/non-english Del: in docs -- https://master.php.net/note/delete/80162/in+docs Del: other reasons-- https://master.php.net/note/delete/80162 Reject -- https://master.php.net/note/reject/80162 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134651) next »