Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Traitsについて

1,925 views

Published on

2008/03/16に開催されたPHP懇親会での発表資料。

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Traitsについて

  1. 1. Traitsについて 小山 哲志 koyama@hoge.org 2008/03/16 PHP懇親会 1
  2. 2. 発表者について小山 哲志(株)ビート・クラフト所属 CNET Japanトラックバックサーバ OCNブログ人 Agilemedia Network広告配信サーバid:koyhogePHP歴は9年くらい 2
  3. 3. TraitsStefan Marr氏がinternalsに提案した新たな構文 http://news.php.net/php.internals/35562 2008/02/18Request for Comments: Traits for PHP http://www.stefan-marr.de/artikel/rfc-traits-for- php.html 3
  4. 4. <?php class Base {文法の基本 public function sayHello() { echo Hello ; } } trait SayWorld { public function sayHello() { parent::sayHello(); echo World!; } } class MyHelloWorld extends Base { use SayWorld; } $o = new MyHelloWorld(); $o->sayHello(); // echos Hello World! ?> 4
  5. 5. <?php複数use trait Hello { public function sayHello() { echo Hello ; } } trait World { public function sayWorld() { echo World; } } class MyHelloWorld { use Hello, World; public function sayExclamationMark() { echo !; } } $o = new MyHelloWorld(); $o->sayHello(); $o->sayWorld(); $o->sayExclamationMark(); // Results eventually in: Hello World! 5
  6. 6. <?php trait Hello {mix-in public function sayHello() { echo Hello ; } } trait World { public function sayWorld() { echo World!; } } trait HelloWorld { use Hello, World; } class MyHelloWorld { use HelloWorld; } $o = new MyHelloWorld(); $o->sayHello(); $o->sayWorld(); // Results eventually in: Hello World! ?> 6
  7. 7. Stefanの意図 Well, think this would be a Mixinmechanism like in Ruby. 7
  8. 8. RFCその後建設的な議論が進む opcodeへの影響は? 構文のPHPらしさ現在は議論停止中(またかよ) 8

×