Created
September 27, 2016 05:08
-
-
Save sotarok/7ed7890c4ea2b64e52f02dc1354c5ab8 to your computer and use it in GitHub Desktop.
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 Banner | |
{ | |
private $x; | |
public $y; | |
public static function factory() | |
{ | |
$self = new Banner(); | |
$self->z = 1; | |
$self->y = 2; | |
$self->x = 3; // ← Private なのに書き込める | |
// 同じクラスの中のstaticメソッドとはいえ本当はスコープ外からの書き込み | |
return $self; | |
} | |
} | |
$b = Banner::factory(); | |
var_dump($b); | |
$b2 = new Banner(); | |
$b2->x = 1; // 当然fatal | |
// Fatal error: Cannot access private property Banner::$x | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment