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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
44 - 31 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC