Skip to content

Instantly share code, notes, and snippets.

@rafaelss
Created September 2, 2008 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelss/8426 to your computer and use it in GitHub Desktop.
Save rafaelss/8426 to your computer and use it in GitHub Desktop.
Example of new PHP6 syntax
<?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