About how initialize implements the assumption that class a, B, base, and a and B inherit base,
A and B allow a method initialize ();
If new N times:
$ Obj = new ();
$ Obj = new ();
$ Obj = new ();
$ Obj = new B ();
$ Obj = new B ();
$ Obj = new B ();
Execute only one a-> initialize (); and one B-> initialize ();
Initialize mainly replaces the _ construct method in the framework.
Phalcon implements this function, but phalcon is a framework written in C. can PHP achieve this effect?
Reply to discussion (solution)
class bass { function __construct() { $this->_initialize(); } function _initialize() { static $v; @$v++; if($v == 1 && method_exists($this, 'initialize')) $this->initialize(); }}class a extends bass { function initialize() { echo __CLASS__; }}class b extends bass { function initialize() { echo __CLASS__; }}$obj = new a();$obj = new a();$obj = new a();$obj = new b();$obj = new b();$obj = new b();
AB
class bass { function __construct() { $this->_initialize(); } function _initialize() { static $v; @$v++; if($v == 1 && method_exists($this, 'initialize')) $this->initialize(); }}class a extends bass { function initialize() { echo __CLASS__; }}class b extends bass { function initialize() { echo __CLASS__; }}$obj = new a();$obj = new a();$obj = new a();$obj = new b();$obj = new b();$obj = new b();
AB
@ $ V ++;
Why does "@" match this sentence?