#33657 [WFx]: Function to determine whether a method is called statically

From: Date: Tue, 12 Jul 2005 10:44:53 +0000
Subject: #33657 [WFx]: Function to determine whether a method is called statically
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-81725@lists.php.net to get a copy of this message
 ID:               33657
 User updated by:  tonvandenheuvel at gmail dot com
 Reported By:      tonvandenheuvel at gmail dot com
 Status:           Wont fix
 Bug Type:         Feature/Change Request
 Operating System: Linux
 PHP Version:      4.4.0
 New Comment:

But then there is no need for debug_backtrace to expose the 'type'
information in the first place?

You're right of course, I should rethink my design.


Previous Comments:
------------------------------------------------------------------------

[2005-07-12 12:37:12] derick@php.net

You should never have to test if a function is static or not - if you
have to your design is broken.

------------------------------------------------------------------------

[2005-07-12 12:17:56] tonvandenheuvel at gmail dot com

Description:
------------
Currently, I'm using this function to determine whether a function is
called statically:

function IsCalledStatically() {
    $debugBt = debug_backtrace();

    return $debugBt[1]['type'] == '::';
}

Having to rely on the debugger is not very efficient here. Other
methods checking whether $this is set are not fool proof in a situation
where a class' method is called statically from another class method
where $this is defined (possibly within the same class!).



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33657&edit=1


Thread (3 messages)

« previous php.bugs (#81725) next »