36. メソッドチェイン
(をするとモダンだよ,という意味ではなく,
できるよ,というだけの話)
<?php
class Hoge
{
...
function fuga() { ... return $this; }
function piyo() { ... return $this; }
function poyo() { return $some_value; }
}
$hoge = new Hoge();
$value = $hoge->fuga()->piyo()->poyo();
37. インターフェース
class Members implements Iterator
{
private $m = array(
'早乙女アルト' => array(16, '中村悠一',),
'ランカ・リー' => array(15, '中島愛',),
'シェリル・ノーム' => array(17, '遠藤綾',),
);
public function key() { return key($this->m);}
public function current() {return current($this->m); }
public function next() { next($this->m); }
public function rewind() {reset($this->m);}
public function valid() {return $this->current() !==
false; }
}
foreach (new Members as $k => $v) {
echo $k, ": ", $v[0], "歳, CV:", $v[1], PHP_EOL;
}
38. インターフェース
class Members implements Iterator
{
private $m = array(
'早乙女アルト' => array(16, '中村悠一',),
'ランカ・リー' => array(15, '中島愛',),
'シェリル・ノーム' => array(17, '遠藤綾',),
);
早乙女アルト: 16歳,{ CV:中村悠一
public function key() return key($this->m);}
ランカ・リー: 15歳, {CV:中島愛 }
public function current() {return current($this->m); }
public function next() next($this->m);
シェリル・ノーム: 17歳, CV:遠藤綾
public function rewind() {reset($this->m);}
public function valid() {return $this->current() !==
false; }
}
foreach (new Members as $k => $v) {
echo $k, ": ", $v[0], "歳, CV:", $v[1], PHP_EOL;
}
57. SPL (spl_autoload_register)
class Al {
public static function load($name) {
$fn = $name . ".php";
if (file_exists($fn))
require_once $fn;
}
public static function loadClass($name) {
$fn = $name . ".class.php";
if (file_exists($fn))
require_once $fn;
}
}
spl_autoload_register('Al::load');
spl_autoload_register('Al::loadClass');
58. SPL (spl_autoload_register)
class Al {
public static function load($name) {
$fn = $name . ".php";
if (file_exists($fn))
require_once $fn;
}
public static function loadClass($name) {
$fn = $name . ".class.php";
if (file_exists($fn))
require_once $fn;
}
}
spl_autoload_register('Al::load');
spl_autoload_register('Al::loadClass');
61. SimpleXML
<?php
$url =
'http://twitter.com/statuses/public_timeli
ne.rss';
$s = simplexml_load_file($url);
foreach ($s->xpath('//item/title') as $t) {
echo $t, PHP_EOL;
}
PurpleTyger9: just started playing Halo 3. http://raptr.com/marioa9
Kell_Christie: I REMEMBER WHEN WE BOOKED @nickiminaj BACK AT LA RUMBA IN THE
SUMMER!!!ZzzzZZoooOOOOooo SHE'S A REAL SHOWSTOPPER :-)
GemCrowley: @Princess_Zo You should come. $4 drinks
02PERSONS: @justinbieber so tomorrow at 7? ;D
RuoXO: @hushiana セイクリッド2ってタイトルは聞いたことあるけど、面白いのか。
...
ちょっと調べてみよう(`・ω・´)