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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat May 11 03:01:29 2024 UTC