Created
September 28, 2013 13:56
-
-
Save hirak/6742321 to your computer and use it in GitHub Desktop.
コンストラクタを簡単に書く ref: http://qiita.com/Hiraku/items/84156e0ed0dc0937e44c
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 Point | |
{ | |
private $x, $y; | |
public function __construct($this->x, $this->y); | |
} |
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 Foo | |
{ | |
private $a, $b, $c, $d; | |
function __construct($a, $b, $c, $d) | |
{ | |
foreach (get_defined_vars() as $key => $val) $this->$key = $val; | |
} | |
} |
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 Foo | |
{ | |
private $_a, $_b, $_c, $_d; | |
function __construct($a, $b, $c, $d) | |
{ | |
foreach (get_defined_vars() as $key => $val) $this->{"_$key"} = $val; | |
} | |
} |
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 Foo | |
{ | |
private $a,$b,$c,$d; | |
function __construct($a, $b, $c, $d) | |
{ | |
$this->a = $a; | |
$this->b = $b; | |
$this->c = $c; | |
$this->d = $d; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment