php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51554 Identifies if a call is static ou 'objective'
Submitted: 2010-04-14 03:07 UTC Modified: 2010-04-14 09:39 UTC
From: david71rj at gmail dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david71rj at gmail dot com
New email:
PHP Version: OS:

 

 [2010-04-14 03:07 UTC] david71rj at gmail dot com
Description:
------------
If a call a method as static, how I can test if is a static call or objective?

Well, I think about "is_static_call()", example:

class A {
  public function test(){
    if(is_static_call()){
      echo 'Static method';
    }
    else {
      echo 'Objective method';
    }
  }
}

A::test(); // Static method
$a = new A;
$a->test(); // Objective method

Currently I use a 'workarround' for this problem:

if($this && get_class($this) === get_class()){
  // Objective method
}

This is my sugestion.
Bye.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-14 09:39 UTC] degeberg@php.net
-Status: Open +Status: Wont fix
 [2010-04-14 09:39 UTC] degeberg@php.net
You shouldn't interchange static and non-static methods. If you need to call a method statically, mark it as static. Your code below will give an E_STRICT error.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC