Skip to content

Instantly share code, notes, and snippets.

@sotarok
Created September 27, 2016 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sotarok/7ed7890c4ea2b64e52f02dc1354c5ab8 to your computer and use it in GitHub Desktop.
Save sotarok/7ed7890c4ea2b64e52f02dc1354c5ab8 to your computer and use it in GitHub Desktop.
<?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