Created
September 2, 2008 16:10
-
-
Save rafaelss/8426 to your computer and use it in GitHub Desktop.
Example of new PHP6 syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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') | |
) | |
) | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment