Req #61147 [Opn->Sus]: No conflict resolution for properties in traits

From: Date: Tue, 21 Feb 2012 09:26:36 +0000
Subject: Req #61147 [Opn->Sus]: No conflict resolution for properties in traits
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-167686@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61147&edit=1 ID: 61147 Updated by: gron@php.net Reported by: greywire at gmail dot com Summary: No conflict resolution for properties in traits -Status: Open +Status: Suspended Type: Feature/Change Request Package: Class/Object related Operating System: MacOS X 10.7 PHP Version: 5.4.0RC8 Block user comment: N Private report: N New Comment: Unfortunately, the solution is not easy at all. One reason is the dynamic nature of PHP. You can easily access properties based on their string name: $foo = 'bar'; $this->$foo = 'foobar'; For exactly the same reason, we do NOT provide 'renaming'. The conflict resolution for methods allows to introduce an alias. Nothing more. An alias is a new name pointing to an unchanged method-body. (If you think about what that means, note that it breaks recursion in typical cases.) Thus, your proposal does not work with the current semantics. It would only result in a new property in the class that is never actually used. So far, we refrained from adding any of the constructs proposed in literature, since they would add considerable complexity. From time to time there have been proposals for related features that could make it into a future version of PHP, but for the moment being, I do not see how we can make this work without changing the nature of PHP. Suggestions are welcome of course. Thanks Stefan Previous Comments: ------------------------------------------------------------------------ [2012-02-20 18:59:00] greywire at gmail dot com Description: ------------ There is no way to resolve a conflict in two used traits with the same property. The resolution method used to resolve conflicting method names should be able to be used similarly on properties. I realize this may be the intended behavior to discourage use of properties in traits as properties were not originally intended in traits, but since properties are allowed, there should be a way to resolve the conflict, and the solution is simple and fits with existing syntax. Test script: --------------- <?php trait testone { public $test; } trait testtwo { public $test; } //** this should work but doesn't class traittest { use testtwo, testone { testone::$test insteadof testtwo; testtwo::$test as $testalso; } } ?> Expected result: ---------------- No errors or warnings. Actual result: -------------- Parse error: syntax error, unexpected '$test' (T_VARIABLE), expecting identifier (T_STRING) in index.php on line 14 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61147&edit=1

« previous php.bugs (#167686) next »