# Trait behavior when providing a new name while no conflict exists

- Thread: https://externals.io/message/50347
- Original archive: https://news-web.php.net/php.internals/50347
- Started by Patrick ALLAERT on 2010-11-18T15:01:56+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #50347 — Patrick ALLAERT — 2010-11-18T15:01:56+00:00

URL: https://externals.io/message/50347#50347

Hi,

Is this intended not being able to give a new name to a method even in
case of no conflict?
In the following example, I try to provide the name "sayIt"
additionally to "saySomething" from trait "Hello":

<?php
trait Hello {
   public function saySomething() {
     echo 'Hello';
   }
}

class MyHello{
   use Hello {
         Hello::saySomething as sayIt;
   }
}
?>

The following error message is shown while running it:

Fatal error: Failed to add aliased trait method (sayIt) to the trait
table. There is probably already a trait method with the same name in
%s on line %d

The error message might be misleading even if it should only be
available in case of conflict.

Regards,

-- 
Patrick Allaert
---
http://code.google.com/p/peclapm/ - Alternative PHP Monitor

---

## #50366 — Stefan Marr — 2010-11-18T18:00:51+00:00

URL: https://externals.io/message/50347#50366 · In reply to: #50347

Hi Patrick:



> Hi,
> 
> Is this intended not being able to give a new name to a method even in
> case of no conflict?
> In the following example, I try to provide the name "sayIt"
> additionally to "saySomething" from trait "Hello":
> 
> <?php
> trait Hello {
>   public function saySomething() {
>     echo 'Hello';
>   }
> }
> 
> class MyHello{
>   use Hello {
>         Hello::saySomething as sayIt;
>   }
> }
> ?>

Thanks for catching this, it is a bug.
It works without the Hello:: part and it should also work with the Hello::.

Fixed with the following commit: http://svn.php.net/viewvc?view=revision&revision=305512

Best regards
Stefan


-- 
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax:   +32 2 629 3525
