PHPのオブジェクトはnewできる
なんか動いたのでメモ。
<?php class Hoge { public $str; public function __construct($str) { echo "__construct() is called.\n"; $this->str = $str; } } $hoge = new Hoge("hoge"); print_r($hoge); $fuga = new $hoge("fuga"); // ★オブジェクトにnewする print_r($fuga);
__construct() is called.
Hoge Object
(
[str] => hoge
)
__construct() is called.
Hoge Object
(
[str] => fuga
)new selfとか、new staticが動くからかな。