Created
March 9, 2014 08:57
-
-
Save uzulla/9444783 to your computer and use it in GitHub Desktop.
「継承できるテンプレートとは」(ネタです)
This file contains hidden or 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 | |
class Mother { | |
static $html = ' | |
<html> | |
<body> | |
{{content}} | |
</body> | |
</html> | |
'; | |
public function __construct($my_name=null, $var=null){ | |
$class_name = (is_null($my_name)) ? get_called_class() : $my_name; | |
$class_name::$html = (!is_null($var)) ? preg_replace('/{{content}}/', $var, $class_name::$html) : $class_name::$html; | |
$parent_list = array_keys(class_parents($class_name)); | |
if(!empty($parent_list)) | |
$parent_list[0]::__construct($parent_list[0], $class_name::$html); | |
else | |
echo $class_name::$html; | |
} | |
} | |
class Child extends Mother { | |
static $html = 'Hello {{content}}'; | |
} | |
class GrandChild extends Child { | |
static $html = 'world!!'; | |
} | |
// Execute | |
new GrandChild(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ php funny.php