fork download
  1. <?php
  2.  
  3. class アニマルガール
  4. {
  5.  
  6. const とくいなんだねー = [
  7. 'わーい',
  8. 'すごーい'
  9. ];
  10.  
  11. protected $おぼえてること = [];
  12.  
  13. private final function __construct()
  14. {}
  15.  
  16. protected static function サンドスター()
  17. {
  18. $class_path = get_called_class();
  19. return new $class_path();
  20. }
  21.  
  22. public static function __callStatic($method, $arguments)
  23. {
  24. return ($instance ?? $instance = static::サンドスター())->$method();
  25. }
  26.  
  27. public function __call($method, $arguments)
  28. {
  29. $this->おぼえてること[] = $method !== 'とくい' ? $method : (new class($arguments[0]) {
  30.  
  31. const さいしょのおやくそく = '君は%sがとくいなフレンズなんだね!!';
  32.  
  33. const すごいおやくそく = '%sができるフレンズなんだー!!';
  34.  
  35. public $とくい = null;
  36.  
  37. public $ちょっとまえ = アニマルガール::とくいなんだねー[0];
  38.  
  39. public function __construct($とくい)
  40. {
  41. $this->とくい = $とくい;
  42. }
  43.  
  44. public function __invoke()
  45. {
  46. return $this->とくい;
  47. }
  48.  
  49. public function __toString()
  50. {
  51. $そうなんだー = sprintf($this->ちょっとまえ === アニマルガール::とくいなんだねー[1] ? self::すごいおやくそく : self::さいしょのおやくそく, $this->とくい);
  52. $this->ちょっとまえ = アニマルガール::とくいなんだねー[0];
  53. return $そうなんだー;
  54. }
  55. });
  56.  
  57. return $this;
  58. }
  59.  
  60. public function __invoke()
  61. {
  62. return $this->おぼえてること;
  63. }
  64.  
  65. public function __toString()
  66. {
  67. $ちょっとまえ = null;
  68. foreach ($this->おぼえてること as $じゅんばん => $おぼえてること) {
  69. if (is_object($おぼえてること)) {
  70. $this->おぼえてること[$じゅんばん]->ちょっとまえ = $ちょっとまえ;
  71. } elseif (in_array($おぼえてること, アニマルガール::とくいなんだねー, true)) {
  72. $ちょっとまえ = $おぼえてること;
  73. }
  74. }
  75. return implode(\PHP_EOL, $this->おぼえてること) . \PHP_EOL;
  76. }
  77. }
  78.  
  79. echo アニマルガール::わーい()->すごーい()->たのしー()->とくい('クソリプ');
  80.  
  81. echo アニマルガール::わーい()->とくい('クソリプ')->すごーい();
  82.  
  83. echo アニマルガール::すごーい()->とくい('クソリプ')->わーい()->たーのしー();
  84.  
  85.  
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
わーい
すごーい
たのしー
クソリプができるフレンズなんだー!!
わーい
君はクソリプがとくいなフレンズなんだね!!
すごーい
すごーい
クソリプができるフレンズなんだー!!
わーい
たーのしー