php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50289 method_exists doesn't work on "self"
Submitted: 2009-11-24 21:37 UTC Modified: 2016-01-15 13:53 UTC
From: soapergem at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.1 OS: Windows XP
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: soapergem at gmail dot com
New email:
PHP Version: OS:

 

 [2009-11-24 21:37 UTC] soapergem at gmail dot com
Description:
------------
method_exists doesn't work if you pass in a callback with a reference to "self". Yet call_user_func *does* work if you pass in a callback with a reference to "self". This is inconsistent and probably not intentional.

Reproduce code:
---------------
<?php
class Test
{
    public static function check_method()
    {
        var_dump(method_exists('self', 'output'));
    }
    public static function run_method()
    {
        call_user_func(array('self', 'output'));
    }
    public static function output()
    {
        echo 'this works';
    }
}
Test::check_method();
Test::run_method();
?>

Expected result:
----------------
bool(true)
this works

Actual result:
--------------
bool(false)
this works

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-25 07:52 UTC] jani@php.net
callback != object or class name

There is no bug here.
 [2016-01-15 13:53 UTC] danack@php.net
Hi,

Using this:
method_exists(self::class, "method")

gives the result you appear to want.

Changing the behaviour of callable with respect to the string 'self' will require an RFC, which I plan to do for PHP 8. https://wiki.php.net/rfc/consistent_callables
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 17:01:28 2025 UTC