Re: Urgent patch for traits in PHP 5.4
| From: | Dmitry Stogov | Date: | Mon, 16 Jan 2012 06:26:52 +0000 |
| Subject: | Re: Urgent patch for traits in PHP 5.4 | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-57370@lists.php.net to get a copy of this message | ||
Stas,
Thank you for looking into it and finding out a new problem :)
I'll take a look into it and will try to fix.
Dmitry.
On 01/13/2012 10:53 PM, Stas Malyshev wrote:
Hi!As I understood the copying was done only for proper handling of __CLASS__ constant in trait methods. I think it's too radical solution. I've introduced ZEND_CLASS_NAME instruction instead and made op_arrays to share their opcodes (in the same way as inherited methods). The only difference that methods from traits may be renamed.I've done some checks and discovered __CLASS__ behaves somewhat strangely with traits. COnsider this code: <? trait foo { public $bar = __CLASS__; function bar() { var_dump($this->bar); } } class foofoo { use foo; } class foofoo2 { use foo; } $a = new foofoo(); $a->bar(); $a = new foofoo2(); $a->bar(); echo "OK!"; Before the patch, it prints $this->bar as NULL. After the patch, I get: Fatal error: Invalid binding type in - on line 5 Both behaviors seem to be wrong, as __CLASS__ works as constant in regular classes. Looks like even before the patch __CLASS__ handling wasn't correct, but patch also seems to break something.