Last active
November 18, 2017 10:09
-
-
Save kuredev/b173ca5bba0f58bc4d25780fe9434959 to your computer and use it in GitHub Desktop.
__set(マジックメソッド)の小さなメモ
This file contains hidden or 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 Test{ | |
private $arr; | |
/** | |
* @param $v1 プロパティの名前 | |
* @param $v2 値 | |
*/ | |
public function __set($v1, $v2){ | |
echo "__set".PHP_EOL; | |
var_dump($v1); | |
var_dump($v2); | |
$this->arr[$v1] = $v2; | |
} | |
public function getArr(){ | |
return $this->arr; | |
} | |
} | |
$test = new Test(); | |
$test->hoge = 10; | |
$test->age = 100; | |
var_dump($test->getArr()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
存在しないプロパティにアクセスしようとしたときに呼ばれる。
実行結果