rafaelss (owner)

Revisions

gist: 8426 Download_button fork
public
Description:
Example of new PHP6 syntax
Public Clone URL: git://gist.github.com/8426.git
Embed All Files: show embed
PHP #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
function html($closure) {
    return tag('html', func_get_args());
}
 
function head($closure) {
    return tag('head', func_get_args());
}
 
function title($closure) {
    return tag('title', func_get_args());
}
 
function body($closure) {
    return tag('body', func_get_args());
}
 
function p($closure) {
    return tag('p', func_get_args());
}
 
function tag($name, array $closures) {
    $html = "<{$name}>";
    foreach($closures as $closure) {
        if($closure instanceof Closure) {
            $html .= $closure();
        }
        else {
            $html .= $closure;
        }
    }
    $html .= "</{$name}>";
    return $html;
}
 
echo html(
    head(
        title('Titulo da Pagina')
    ),
 
    body(
        p('Hello World'),
        p(
            'Outro Paragrafo',
            p('Um subparagrafo agora')
        )
    )
);
?>