|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-09-07 05:20 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 01:00:02 2025 UTC |
@reeze.xia, yes, this weird behavior, because we can do somethink like this: function __construct() { $args = func_get_args(); // do something with $args } It seems like a bug.construct is a fcall after ZEND_NEW opcode, if there is construct, then no fcall at all(thus no argument substituation). <?php class Foo { } function a() { die("DIE ME!"); } $b = new Foo(a()); ?> I'd like to mark this as a DOC bug, since agrumets eval is useless in most of the times.