Code Comments
Programming Forum and web based access to our favorite programming groups.Is it possible to determine method that calls another method ?
for example:
class A {
private function One() {
// do something depending on calling method
}
public function Two() {
return $this->One();
}
public function Three() {
return $this->One();
}
}
Apart from including method (__METHOD__) in function call: $this-
>One(__METHOD__) ?
Pugi!
Post Follow-up to this messagePugi! wrote:
> Is it possible to determine method that calls another method ?
> for example:
>
> class A {
> private function One() {
> // do something depending on calling method
> }
>
> public function Two() {
> return $this->One();
> }
>
> public function Three() {
> return $this->One();
> }
> }
>
> Apart from including method (__METHOD__) in function call: $this-
>
> Pugi!
>
No, but why would you want to? If you want to do something different,
create a different method.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Post Follow-up to this messageOn 27 mrt, 13:15, Jerry Stuckle <jstuck...@attglobal.net> wrote: > Pugi! wrote: > > > > > > > No, but why would you want to? If you want to do something different, > create a different method. > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstuck...@attglobal.net > ================== Class that can create, modify, delete, move a file (physical) and its extensive metadata (database). A validate method for the input (an array) will be different for each action, but not completely. The calling method could be the means to distinguish between them. Pugi!
Post Follow-up to this messagePugi! wrote: > On 27 mrt, 13:15, Jerry Stuckle <jstuck...@attglobal.net> wrote: > > Class that can create, modify, delete, move a file (physical) and its > extensive metadata (database). A validate method for the input (an > array) will be different for each action, but not completely. The > calling method could be the means to distinguish between them. > > Pugi! > Then you should have different validate methods, and call the appropriate one. Your code will be much cleaner. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
Post Follow-up to this messagePugi! wrote: > Is it possible to determine method that calls another method ? use info from debug_backtrace() But I think this is bad way. Try to rewrite your code to avoid this.
Post Follow-up to this messagePugi! wrote:
> Is it possible to determine method that calls another method ?
> for example:
>
> class A {
> private function One() {
> // do something depending on calling method
> }
>
> public function Two() {
> return $this->One();
> }
>
> public function Three() {
> return $this->One();
> }
> }
>
> Apart from including method (__METHOD__) in function call: $this-
>
> Pugi!
You could pass the name of the caller (or whatever you want to identify
the caller with) as a parameter.
$this->One("Fred");
$this->One("Barney");
It would make more sense than a raw method name anyway.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.