I'm getting some apparently strange behaviour* while trying to concatenate strings in PHP.
I've pared down the following code to show where the problem lies:
class htmlElement
{
private $tagName;
public function __construct($tagName)
{
$this->setTagName($tagName);
}
public function setTagName($tagName)
{
$this->tagName = is_string($tagName) ? $tagName : NULL;
}
public function getTagName()
{
return (string)$this->tagName;
}
public function getHtml()
{
$tagName = $this->getTagName();
$html = "<" . $tagName . "></" . $tagName . ">";
return $html;
}
}
$div = new htmlElement("div");
var_dump($div->getHtml());
The result of the var dump is:
string(11) "
"
The length (11) seems to be correct, but where is the text?!
*I assume it's not actually strange behaviour, and that I'm missing something really obvious!