php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33657 Function to determine whether a method is called statically
Submitted: 2005-07-12 12:17 UTC Modified: 2005-07-12 12:44 UTC
From: tonvandenheuvel at gmail dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.4.0 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tonvandenheuvel at gmail dot com
New email:
PHP Version: OS:

 

 [2005-07-12 12:17 UTC] 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!).


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-12 12:37 UTC] 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:44 UTC] tonvandenheuvel at gmail dot com
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 07:01:30 2025 UTC