Skip to content

Instantly share code, notes, and snippets.

@suin
Created December 2, 2012 07:43
Show Gist options
  • Save suin/4187625 to your computer and use it in GitHub Desktop.
Save suin/4187625 to your computer and use it in GitHub Desktop.
parent::parent::parentコンストラクタパターン
<?php
class Foo
{
public function __construct()
{
$this->value = __CLASS__;
}
}
class Bar extends Foo
{
public function __construct()
{
// 俺のサブクラスには、Fooのコンストラクタを使わせないぜ!
}
}
class Baz extends Bar
{
public function __construct()
{
// 無駄無駄ァ!!
Foo::__construct();
}
}
var_dump(new Baz);
@suin
Copy link
Author

suin commented Dec 2, 2012

アンチパターンです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment