I've only seen this syntax once before and can't find it anywhere on the internet. Has anyone else seen Php syntax like this?
<?php
/**
* Created by PhpStorm.
* Date: 10/5/15
* Time: 3:11 PM
*/
$tag = $_POST['tag'];
$tag
->DIV(array(
'id' => 'home' ,
) , $tag()
->DIV(array(
'class' => 'headLine' ,
)
) , $tag()
);
This code seems a chain method or fluent interface, every time you call the method DIV()
it return itself.
<?php
Class Element{
private $elements = [];
public function add($e){
$this->elements[] = $e;
return $this;
}
public function show(){
echo '<pre>';
print_r($this->elements);
}
}
$e = new Element();
$e->add('<form action="register.php" method="post">')
->add('<input type="text" name="id" /> ')
->add('<input type="text" name="name" />')
->add('<input type="text" name="email" />')
->add('<input type="password" name="password" />')
->add('<input type="submit" name="send" />')
->add('</form>')
->show();