SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
PHP5.5についてのメモ
作成者 ina_ryu
PHP5.5新機能
ジェネレータの追加(5.5の目玉機能)
finallyキーワードの追加
foreachがlist()に対応
empty()が任意の式に対応
arrayとstringのデリファレンス
パスワードハッシュAPIや関数・クラスなどの新規追加
ジェネレータの追加
ジェネレータ関数の見た目は普通の関数と同じ
ジェネレータ関数の肝となるのがyieldキーワード
違うのは値を返すのではなく、必要な値をyieldする
ジェネレータが値をyieldした時点の状態を保存してお
き次に必要になったときにそこから再開
yieldキーワードについて
yield文の見た目はreturn文とほぼ同じ
ただし、return文の場合は関数の実行を終了して値を返すが
yield文は違う
yield文の場合はジェネレータを呼び出しているループに値を
戻してジェネレータ関数の実行を一時停止
内部的に整数の連番キーがyieldする値とペアになり、配列と
同じようになる
数値添字の配列だけでなく連想配列にも対応
<?php
/**
* ジェネレータテスト
*/
function test()
{
for ($i = 1; $i <= 3; $i++) {
// yieldを繰り返す間、$iの値が維持される
yield $i;
}
}
$test = test();
foreach ($test as $value) {
echo $value . “n”;
}
// 結果
// 1
// 2
// 3
finallyキーワードの追加
catchブロックの後にfinallyブロックを指定できる
tryおよびcatchブロックの後で常に実行される
例外がスローされたかどうかは関係なく実行される
finallyブロックを実行してから通常の処理を続行
foreachがlist()に対応
foreach構文にlist()が使える
ネストした配列を個別の変数に展開できる
<?php
/**
* foreachでlist()対応テスト
*/
$array = [
[1, 2],
[3, 4],
];
foreach ($array as list($a, $b)) {
echo “A: $a; B: $bn”;
}
// 結果
// A: 1; B: 2
// A: 3; B: 4
empty()が任意の式に対応
変数だけでなく任意の式を渡せるようになった
<?php
/**
* empty()の任意の式対応テスト
*/
function test()
{
return false;
}
if (empty(test())) {
echo “hogehogen”;
}
if (empty(true)) {
echo “fugafugan”;
}
// 結果
// fugafuga
arrayとstringのデリファレンス
個々の要素や文字に直接アクセスできるようになる
<?php
/**
* arrayとstringのデリファレンステスト
*/
echo “Array dereferencing: “;
echo [1, 2, 3][0];
echo “n”;
echo “String dereferencing: “;
echo ‘PHP’[0];
echo “n”;
// 結果
// Array dereferencing: 1
// String dereferencing: P
関数やクラスの新規追加など
関数やクラスの新規追加についてはマニュアルを参照
例えば、array_columnやboolvalが追加された
ご清聴ありがとうございました。

Weitere ähnliche Inhalte

Was ist angesagt?

そしてjsの基礎へ戻る#4
そしてjsの基礎へ戻る#4そしてjsの基礎へ戻る#4
そしてjsの基礎へ戻る#4Shingo Inoue
 
WWDC 旅行の余談と Swift Open Hours 3 - Swift ラボで聞いてきた話 #cocoa_kansai
WWDC 旅行の余談と Swift Open Hours 3 - Swift ラボで聞いてきた話 #cocoa_kansaiWWDC 旅行の余談と Swift Open Hours 3 - Swift ラボで聞いてきた話 #cocoa_kansai
WWDC 旅行の余談と Swift Open Hours 3 - Swift ラボで聞いてきた話 #cocoa_kansaiTomohiro Kumagai
 
エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7Tetsuya Morimoto
 
プログラミングの基礎振り返りスライド1
プログラミングの基礎振り返りスライド1プログラミングの基礎振り返りスライド1
プログラミングの基礎振り返りスライド1sunotora
 
Replace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JPReplace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JPAkira Takahashi
 
Fork/Join Framework。そしてLambdaへ。
Fork/Join Framework。そしてLambdaへ。Fork/Join Framework。そしてLambdaへ。
Fork/Join Framework。そしてLambdaへ。Yuichi Sakuraba
 
ジェネリクスの基礎と応用 JJUG CCC 2012 Fall
ジェネリクスの基礎と応用 JJUG CCC 2012 Fallジェネリクスの基礎と応用 JJUG CCC 2012 Fall
ジェネリクスの基礎と応用 JJUG CCC 2012 Fallnagise
 
Essential Scala 第5章 シーケンス処理
Essential Scala 第5章 シーケンス処理Essential Scala 第5章 シーケンス処理
Essential Scala 第5章 シーケンス処理Takuya Tsuchida
 
言語処理系入門€6
言語処理系入門€6言語処理系入門€6
言語処理系入門€6Kenta Hattori
 
JavaのGenericsとは?
JavaのGenericsとは?JavaのGenericsとは?
JavaのGenericsとは?Kenji Nakamura
 
error handling using expected
error handling using expectederror handling using expected
error handling using expectedAkira Takahashi
 
ジェネリクスの基礎と クラス設計への応用
ジェネリクスの基礎とクラス設計への応用ジェネリクスの基礎とクラス設計への応用
ジェネリクスの基礎と クラス設計への応用nagise
 
Lisp Tutorial for Pythonista : Day 3
Lisp Tutorial for Pythonista : Day 3Lisp Tutorial for Pythonista : Day 3
Lisp Tutorial for Pythonista : Day 3Ransui Iso
 
メタプログラミングRubyはこの付録が美味しい
メタプログラミングRubyはこの付録が美味しいメタプログラミングRubyはこの付録が美味しい
メタプログラミングRubyはこの付録が美味しいShigeru UCHIYAMA
 

Was ist angesagt? (16)

そしてjsの基礎へ戻る#4
そしてjsの基礎へ戻る#4そしてjsの基礎へ戻る#4
そしてjsの基礎へ戻る#4
 
WWDC 旅行の余談と Swift Open Hours 3 - Swift ラボで聞いてきた話 #cocoa_kansai
WWDC 旅行の余談と Swift Open Hours 3 - Swift ラボで聞いてきた話 #cocoa_kansaiWWDC 旅行の余談と Swift Open Hours 3 - Swift ラボで聞いてきた話 #cocoa_kansai
WWDC 旅行の余談と Swift Open Hours 3 - Swift ラボで聞いてきた話 #cocoa_kansai
 
エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7
 
プログラミングの基礎振り返りスライド1
プログラミングの基礎振り返りスライド1プログラミングの基礎振り返りスライド1
プログラミングの基礎振り返りスライド1
 
Replace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JPReplace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JP
 
Fork/Join Framework。そしてLambdaへ。
Fork/Join Framework。そしてLambdaへ。Fork/Join Framework。そしてLambdaへ。
Fork/Join Framework。そしてLambdaへ。
 
What is template
What is templateWhat is template
What is template
 
ジェネリクスの基礎と応用 JJUG CCC 2012 Fall
ジェネリクスの基礎と応用 JJUG CCC 2012 Fallジェネリクスの基礎と応用 JJUG CCC 2012 Fall
ジェネリクスの基礎と応用 JJUG CCC 2012 Fall
 
Essential Scala 第5章 シーケンス処理
Essential Scala 第5章 シーケンス処理Essential Scala 第5章 シーケンス処理
Essential Scala 第5章 シーケンス処理
 
言語処理系入門€6
言語処理系入門€6言語処理系入門€6
言語処理系入門€6
 
JavaのGenericsとは?
JavaのGenericsとは?JavaのGenericsとは?
JavaのGenericsとは?
 
error handling using expected
error handling using expectederror handling using expected
error handling using expected
 
ジェネリクスの基礎と クラス設計への応用
ジェネリクスの基礎とクラス設計への応用ジェネリクスの基礎とクラス設計への応用
ジェネリクスの基礎と クラス設計への応用
 
Aedlabo program 20150125
Aedlabo program 20150125Aedlabo program 20150125
Aedlabo program 20150125
 
Lisp Tutorial for Pythonista : Day 3
Lisp Tutorial for Pythonista : Day 3Lisp Tutorial for Pythonista : Day 3
Lisp Tutorial for Pythonista : Day 3
 
メタプログラミングRubyはこの付録が美味しい
メタプログラミングRubyはこの付録が美味しいメタプログラミングRubyはこの付録が美味しい
メタプログラミングRubyはこの付録が美味しい
 

Andere mochten auch

Performance Management by Jonathan Westover
Performance Management by Jonathan WestoverPerformance Management by Jonathan Westover
Performance Management by Jonathan WestoverHTPBELARUS
 
Negotiation presentation
Negotiation presentationNegotiation presentation
Negotiation presentationLovebunni20
 
training of Professor Kent Millington (2)
training of Professor Kent Millington (2)training of Professor Kent Millington (2)
training of Professor Kent Millington (2)HTPBELARUS
 
Negotiation presentation
Negotiation presentationNegotiation presentation
Negotiation presentationLovebunni20
 
Technology in the elt class by francisco aguirre
Technology in the elt class by francisco aguirreTechnology in the elt class by francisco aguirre
Technology in the elt class by francisco aguirreFrancisco Aguirre
 
Guatemala 2011
Guatemala 2011Guatemala 2011
Guatemala 2011grugie13
 
HTP Session 1-Effective Interviewing to the Moneyball Approach to Selection
HTP Session 1-Effective Interviewing to the Moneyball Approach to SelectionHTP Session 1-Effective Interviewing to the Moneyball Approach to Selection
HTP Session 1-Effective Interviewing to the Moneyball Approach to SelectionHTPBELARUS
 
Employee Motivation by Pr. Jonathan Westover
Employee Motivation by Pr. Jonathan WestoverEmployee Motivation by Pr. Jonathan Westover
Employee Motivation by Pr. Jonathan WestoverHTPBELARUS
 
training of Professor Kent Millington
training of Professor Kent Millingtontraining of Professor Kent Millington
training of Professor Kent MillingtonHTPBELARUS
 
Dubograev minsk pvt_mistakes re legal strategy 2015_short
Dubograev minsk pvt_mistakes re legal strategy 2015_shortDubograev minsk pvt_mistakes re legal strategy 2015_short
Dubograev minsk pvt_mistakes re legal strategy 2015_shortHTPBELARUS
 
Presentation2
Presentation2Presentation2
Presentation2sam316
 
Fotos 1r Equip 2007 08
Fotos 1r Equip 2007 08Fotos 1r Equip 2007 08
Fotos 1r Equip 2007 08marcellus33
 
Maquinas grandes, pequeñas y largas
Maquinas grandes, pequeñas y largasMaquinas grandes, pequeñas y largas
Maquinas grandes, pequeñas y largasjuganda
 
Modelos De Maridos
Modelos De MaridosModelos De Maridos
Modelos De Maridosluisa matos
 
Quinta Digital Especial Interminas 2010
Quinta Digital Especial Interminas 2010Quinta Digital Especial Interminas 2010
Quinta Digital Especial Interminas 2010quintadigital
 

Andere mochten auch (20)

Performance Management by Jonathan Westover
Performance Management by Jonathan WestoverPerformance Management by Jonathan Westover
Performance Management by Jonathan Westover
 
Negotiation presentation
Negotiation presentationNegotiation presentation
Negotiation presentation
 
Bookkeeping presentation
Bookkeeping presentationBookkeeping presentation
Bookkeeping presentation
 
training of Professor Kent Millington (2)
training of Professor Kent Millington (2)training of Professor Kent Millington (2)
training of Professor Kent Millington (2)
 
Negotiation presentation
Negotiation presentationNegotiation presentation
Negotiation presentation
 
Technology in the elt class by francisco aguirre
Technology in the elt class by francisco aguirreTechnology in the elt class by francisco aguirre
Technology in the elt class by francisco aguirre
 
Guatemala 2011
Guatemala 2011Guatemala 2011
Guatemala 2011
 
HTP Session 1-Effective Interviewing to the Moneyball Approach to Selection
HTP Session 1-Effective Interviewing to the Moneyball Approach to SelectionHTP Session 1-Effective Interviewing to the Moneyball Approach to Selection
HTP Session 1-Effective Interviewing to the Moneyball Approach to Selection
 
Employee Motivation by Pr. Jonathan Westover
Employee Motivation by Pr. Jonathan WestoverEmployee Motivation by Pr. Jonathan Westover
Employee Motivation by Pr. Jonathan Westover
 
training of Professor Kent Millington
training of Professor Kent Millingtontraining of Professor Kent Millington
training of Professor Kent Millington
 
Dubograev minsk pvt_mistakes re legal strategy 2015_short
Dubograev minsk pvt_mistakes re legal strategy 2015_shortDubograev minsk pvt_mistakes re legal strategy 2015_short
Dubograev minsk pvt_mistakes re legal strategy 2015_short
 
Presentation2
Presentation2Presentation2
Presentation2
 
Fotos 1r Equip 2007 08
Fotos 1r Equip 2007 08Fotos 1r Equip 2007 08
Fotos 1r Equip 2007 08
 
revista
revistarevista
revista
 
Portfolio 4
Portfolio 4Portfolio 4
Portfolio 4
 
Maquinas grandes, pequeñas y largas
Maquinas grandes, pequeñas y largasMaquinas grandes, pequeñas y largas
Maquinas grandes, pequeñas y largas
 
Modelos De Maridos
Modelos De MaridosModelos De Maridos
Modelos De Maridos
 
Quinta Digital Especial Interminas 2010
Quinta Digital Especial Interminas 2010Quinta Digital Especial Interminas 2010
Quinta Digital Especial Interminas 2010
 
Curso 100 Hs Unidade 01
Curso 100 Hs  Unidade 01Curso 100 Hs  Unidade 01
Curso 100 Hs Unidade 01
 
5 formulario tabla cliente
5 formulario tabla cliente5 formulario tabla cliente
5 formulario tabla cliente
 

Php5.5についてのメモ