Edit report at https://bugs.php.net/bug.php?id=63025&edit=1
ID: 63025 Comment by: reeze dot xia at gmail dot com Reported by: hinikato at mail dot ru Summary: Method in trait not called when called as __constructor() argument Status: Open Type: Bug Package: Scripting Engine problem Operating System: Windows 7 x64 PHP Version: 5.4.6 Block user comment: N Private report: N New Comment: There is nothing to do with trait. look http://3v4l.org/eOVRJ class A { /* no constructor public function __construct() {} */ } class B { public function __construct() { die("DIE ME!"); } } $a = new A(new B()); // output nothing. it didn't die with "DIE ME!" since class A didn't have any constructor, so the construct params will not executed the same as: if (false && $it->iWillNotBeExecuted()) { // } I thought this is a document problem :) Previous Comments: ------------------------------------------------------------------------ [2012-09-07 05:20:18] hinikato at mail dot ru Description: ------------ Please see the code below. If I try move the $this->getSomething() to var: $tmp = $this->getSomething(); return new Bar($tmp); it works as expected, however it does not work as shown below. Test script: --------------- class Foo { use TFoo; function test() { $this->getFromTrait(); } } class Bar { function some() { die(__METHOD__); } } trait TFoo { function getFromTrait() { return new Bar($this->getSomething()); } function getSomething() { // Must be called!!! die(__METHOD__); } } (new Foo())->test(); Expected result: ---------------- THe TFoo::getSomething() should be called. Actual result: -------------- The TFoo::getSomething()not called. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63025&edit=1