is it possible to determine method that calls other method ?

This is a discussion on is it possible to determine method that calls other method ? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Is it possible to determine method that calls another method ? for example: class A { private function One() { // do something depending ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-27-2008
Pugi!
 
Posts: n/a
Default is it possible to determine method that calls other method ?

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!
Reply With Quote
  #2 (permalink)  
Old 03-27-2008
Pugi!
 
Posts: n/a
Default Re: is it possible to determine method that calls other method ?

On 27 mrt, 13:15, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Pugi! 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-
> >> One(__METHOD__) ?

>
> > 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.
> 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!
Reply With Quote
  #3 (permalink)  
Old 03-27-2008
Jerry Stuckle
 
Posts: n/a
Default Re: is it possible to determine method that calls other method ?

Pugi! 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-
>> One(__METHOD__) ?

>
> 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
==================

Reply With Quote
  #4 (permalink)  
Old 03-27-2008
Jerry Stuckle
 
Posts: n/a
Default Re: is it possible to determine method that calls other method ?

Pugi! wrote:
> On 27 mrt, 13:15, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> Pugi! 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-
>>>> One(__METHOD__) ?
>>> 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.
>> 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!
>


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
==================

Reply With Quote
  #5 (permalink)  
Old 03-28-2008
Alexey Kulentsov
 
Posts: n/a
Default Re: is it possible to determine method that calls other method ?

Pugi! 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.
Reply With Quote
  #6 (permalink)  
Old 03-29-2008
Preventer of Work
 
Posts: n/a
Default Re: is it possible to determine method that calls other method ?

Pugi! 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-
>> One(__METHOD__) ?

>
> 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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:58 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0