php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36635 is_callable returns true for interfaces
Submitted: 2006-03-06 20:15 UTC Modified: 2006-03-06 20:48 UTC
From: slafontaine at avance dot info Assigned: helly (profile)
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.2 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 !
Your email address:
MUST BE VALID
Solve the problem:
38 - 25 = ?
Subscribe to this entry?

 
 [2006-03-06 20:15 UTC] slafontaine at avance dot info
Description:
------------
When you use is_callable to check if a method is callable on an interface, it returns true which might be because Classes and Interfaces share the same namespace.

Reproduce code:
---------------
interface MyInterface
{
    function callableFunc();
}

if (is_callable(array("MyInterface", "callableFunc"))) {
    print("Is callable!");
    call_user_func(array("MyInterface", "callableFunc"));
} else {
    print("Is NOT callable!");
}

Expected result:
----------------
Is NOT callable!

Actual result:
--------------
Is callable!

Fatal error:  Cannot call abstract method MyInterface::callableFunc() in path/to/file on line ###

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-06 20:48 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The method is indeed callable - if you had an object. And that's the whole issue, try it with abstract methods in abstract classes, that's the same. And that's just because is_callable doesn't verify the scope.

Perhaps we should verify that you actually have an object specified if that is necessary. But that would be a bigger BC break i guess.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 02:01:30 2024 UTC