Created
September 25, 2013 16:21
-
-
Save jun-ya/6702139 to your computer and use it in GitHub Desktop.
FuelPHPでMongoDB使ってるときに調子付いてメソッドチェーンなんかつかってしまうと無駄に横長になってしまう(こんな書き方するなよって話だけど)。けど、php5.4から連想配列が ['foo'=>'bar'] でイケるようになったのでちょっとだけ短く表現できるよ。"array"、"("、")" をタイプするの面倒だもんね(笑)。
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 | |
class Controller_Top extends Controller | |
{ | |
/** | |
* 連想配列を array('foo' => 'bar') で表現したときのダメなメソッドチェーン例。 | |
*/ | |
public function action_mongotest() | |
{ | |
$db = \Mongo_Db::instance(); | |
$res = $db->where(array('foo' => 'bar', 'hoge' => 'huga'))->select(array('hoge_id', 'created_at'))->order_by(array('created_at' => 'asc'))->get('foo_bar'); | |
// ... | |
} | |
/** | |
* php5.4からは array('foo' => 'bar') が ['foo' => 'bar'] と書けるようになったのでちょっとだけ短くなる。 | |
*/ | |
public function action_mongotestphp54() | |
{ | |
$db = \Mongo_Db::instance(); | |
$res = $db->where(['foo' => 'bar', 'hoge' => 'huga'])->select(['hoge_id', 'created_at'])->order_by(['created_at' => 'asc'])->get('foo_bar'); | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment