fork download
  1. <?php
  2.  
  3. class A
  4. {
  5. private $_a;
  6. private $_b;
  7.  
  8. public function __construct($a = null, $b = null)
  9. {
  10. $this->_a = $a;
  11. $this->_b = $b;
  12.  
  13. echo 'Constructed A instance with args: ' . $a . ', ' . $b . "\n";
  14. }
  15.  
  16. public function construct_from_this()
  17. {
  18. $ref = new ReflectionClass($this);
  19. return $ref->newInstance('a_value', 'b_value');
  20. }
  21. }
  22.  
  23. $foo = new A();
  24. $result = $foo->construct_from_this();
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Constructed A instance with args: , 
Constructed A instance with args: a_value, b_value