Last active
December 16, 2015 10:09
-
-
Save k-holy/5418474 to your computer and use it in GitHub Desktop.
日本語でTrait練習
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 | |
namespace 俺の; | |
trait プロパティ実行 | |
{ | |
public function __call($name, $args) | |
{ | |
if (isset($this->{$name}) && is_callable($this->{$name})) { | |
return call_user_func_array($this->{$name}, $args); | |
} | |
} | |
} | |
trait HTML | |
{ | |
public function エスケープ($var) | |
{ | |
return htmlspecialchars($var, ENT_QUOTES, 'UTF-8'); | |
} | |
} | |
class アプリケーション extends \stdClass | |
{ | |
use プロパティ実行; | |
use HTML; | |
public function 爆発しろ($var) | |
{ | |
return sprintf('%s 爆発しろ', $var); | |
} | |
} | |
$アプリケーション = new アプリケーション(); | |
echo get_class($アプリケーション); | |
echo $アプリケーション->爆発しろ('ぴかちゅう'); | |
$アプリケーション->強調 = function($var) { | |
return sprintf('<strong>%s</strong>', $var); | |
}; | |
echo $アプリケーション->強調($アプリケーション->爆発しろ('ぴかちゅう')); | |
$無名関数 = function() { | |
return '<script>alert("こんにちは");</script>'; | |
}; | |
echo $無名関数(); | |
echo $アプリケーション->エスケープ($無名関数()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment