Trait vs magic constants (bug #61033)

From: Date: Tue, 19 Feb 2013 09:37:18 +0000
Subject: Trait vs magic constants (bug #61033)
Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi Internals after quite a long time,

There is an issue in the tracker (#61033 and somewhat related #64239) about magic constants behaviour in aliased trait methods. Stefan classified #61033 as a "feature not a bug" however he suggested to start a discussion about it.

So here's the case: how to get current running method name when in an aliased trait method:

trait T {
 public function method() {
   // __FUNCTION__ is "method"
 }
}

class C {
 use T { method as m; }
 public function method() {}
}

This is all nice and dandy but imagine (among other things) that you want to return a callback to itself from such a method. How would you go about it?

Returning [$this, __FUNCTION__] would be most obvious but it's obviously not what we want. Apart from using debug_backtrace (which has it's own issues; #64239 being one) I don't see any way of doing it.

So: is this a feature or a bug?

And if it really is a feature then either we need another magic const (like suggested in #64239) or (preferably IMO) a method to resolve method name at runtime (a counterpart to get_called_class() - say get_called_method()).

Cheers
Marcin


Thread (1 message)

  • Marcin Kurzyna
« previous php.internals (#65928) next »