0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

アロー演算子の可変関数についてメモ

Last updated at Posted at 2019-06-25

可変関数について簡単にメモ。

ex)
class Person {
    public function sayHello() {
        echo "Hello.";
    }
    
    public function sayEvening() {
        echo "Good evening";
    }
}

$now = intval(date('H'));
if($now <= 16) {
    $greet = "sayHello";    
} else {
    $greet = "sayEvening";    
}

$person = new Person;
$person->$greet();

アロー関数時も、関数名を変数にいれて、

$person->$greet();

このように動的にメソッドを呼ぶことができる。

FWのモデルを呼ぶときにwhereメソッドなのか、andWhereメソッドなのか条件で場合分けするときに使ってみた。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?