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
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: slafontaine at avance dot info
New email:
PHP Version: OS:

 

 [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

Pull Requests

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 Oct 18 03:01:27 2024 UTC