For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > March 2008 > is it possible to determine method that calls other method ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author is it possible to determine method that calls other method ?
Pugi!

2008-03-27, 8:01 am

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!
Jerry Stuckle

2008-03-27, 8:01 am

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

Pugi!

2008-03-27, 8:01 am

On 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!
Jerry Stuckle

2008-03-27, 8:01 am

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

Alexey Kulentsov

2008-03-28, 7:03 pm

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.
Preventer of Work

2008-03-29, 4:04 am

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-
>
> 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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com