php/php-src — pull request #83 by reeze (2012-05-15 04:30:46+00:00)
Title: Fixed bug #61998 (Crash when declare trait after class if user define the same name as aliased one)

Thanks ron for your test script. I've make a minimal reproducible one below:

In class Class1:
newFunc was referred to T::func
func was itself (by overriding);

In trait T
func was referred by T and itself;

--- since class was destroyed by reverse order --
1. Destroy T： will not release the function name defined in trait. since
the Class1 referred to this function.
2. Destroy Class1：it will destroy the alias name since the aliased
function name was referred to it.(this let riginal function name
in trait unreleased and leak).
after destroy function table it will destroy alias info. but alias name was
already destroyed in function table releasing phrase. This cause double free(crash).

Solutions:
1. Copy the whole function will solve the problem. but it was too heavy.
2. Don't change the aliases function's name, since function call are always lookup by hash key name.
but it will make reflection unhappy and can't throw right error message for function.
3. Make a reference in function table if trait function was overrided to avoid releasing problem.
This need to change reflection ignore it.get_defined_functions() & get_delcared_clesses()
use this trick to filter special entry. so we need to change ReflectionClass::getMethods().

in summary I prefer option 3. What do you think?