Re: Urgent patch for traits in PHP 5.4
| From: | Stas Malyshev | Date: | Fri, 13 Jan 2012 18:53:18 +0000 |
| Subject: | Re: Urgent patch for traits in PHP 5.4 | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-57360@lists.php.net to get a copy of this message | ||
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. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227