Jak wyświetlić wartość elementu tablicy lub właściwości obiektu w składni PHP Heredoc
Mam problem z wyświetlaniem wartości tablicy wewnątrz pola wejściowego heredoc. Oto fragment kodu:
class Snippet{
protected $_user;
protected $_class;
protected $_messages;
public function __construct(){
$this->_user = $this->_class = NULL;
$this->createUser();
}
public function createUser(){
$keys = array('user_login','user_email');
$this->_user = $this->_class = array_fill_keys($keys, '');
}
public function userErrors(){
//by default give the login field autofocus
$_class['user_login'] = 'autofocus';
}
public function getForm(){
return <<<HTML
<form id='test' action='' method='post'>
$this->_messages
<fieldset>
<legend>Testing Heredoc</legend>
<ol>
<li>
<label for='user_login'>Username</label>
<input id='user_login' name='user_login' type='text' placeholder='Login name' value=$this->_user[user_login] $this->_class[user_login]>
</li>
</ol>
</fieldset>
</form>
HTML;
}
}
Moje dane wyjściowe dają etykietowane pole wejściowe z wartością wyświetlaną jakoArray[user_login]
. Mogę przypisać tablicę do oddzielenia zmiennych i uzyskać wyjście, którego szukam, ale wydaje się to niepotrzebnym marnotrawstwem. PHP 5.3.5