php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62208 is_callable() returning false if method name is the same as the class name
Submitted: 2012-06-01 15:43 UTC Modified: 2012-06-03 14:23 UTC
From: cidahf at live dot co dot uk Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.3 OS: Ubuntu 12.04
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: cidahf at live dot co dot uk
New email:
PHP Version: OS:

 

 [2012-06-01 15:43 UTC] cidahf at live dot co dot uk
Description:
------------
Using the is_callable function to check the existence of a method using a string 
identifier for the class fails to work as expected when the method name is the 
same as the class name.

Normally, I would use method_exists(), but it doesn't account for whether or not 
the method is accessible.

This bug does not seem to occur on 5.2.5 (tested on codepad).

My exact PHP version is "5.4.3-4~precise+1"

Test script:
---------------
<?php
class Test
{
   public function test ()
   {
   }
}

var_dump (is_callable (array ('Test', 'test')));

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

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-01 16:32 UTC] reeze dot xia at gmail dot com
This is not a bug.

The method the same as class name is legacy class constructor, 
when check like is_callable(array('ClassName', 'classname') means
check whether ClassName:classname() is callable, but the constructor
didn't allow call statically. if you do that, a fatal error will raise.

you could call it as instance method:
is_callable(array(new Test, 'test')) => true;

Thanks
 [2012-06-03 14:23 UTC] felipe@php.net
-Status: Open +Status: Not a bug
 [2012-06-03 14:23 UTC] felipe@php.net
Reeze is right. Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 00:01:29 2024 UTC