php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63578 is_callable returns false with __call
Submitted: 2012-11-22 06:31 UTC Modified: 2012-11-22 08:01 UTC
From: pierre at pcservice dot co dot za Assigned: dmitry (profile)
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: mac & linux
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: pierre at pcservice dot co dot za
New email:
PHP Version: OS:

 

 [2012-11-22 06:31 UTC] pierre at pcservice dot co dot za
Description:
------------
When you have a class that have a __call magic method, when calling is_callable 
with an array and the first argument a string, it returns false.


Test script:
---------------
Class Foo {
    public function __call($method, $args) {}
}

var_dump(is_callable(array('Foo', 'bar')));
var_dump(is_callable(array(new Foo, 'bar')));

Expected result:
----------------
true
true

Actual result:
--------------
false
true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-22 07:08 UTC] laruence@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: dmitry
 [2012-11-22 07:08 UTC] laruence@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

Class Foo {
    public function __call($method, $args) {}
}

Foo::bar();

//result in
Fatal error: Call to undefined method Foo::bar()
 [2012-11-22 07:50 UTC] pierre at pcservice dot co dot za
so when calling is_callable(array('Foo', 'bar')), if the method doesn't exist, 
it only looks for a static method?

with the following

class Controller {

    public function testAction()
    {

    }

    public static function staticAction()
    {

    }

    public function __call($method, $arguments)
    {

    }
}


is_callable(array(new Controller, 'testAction'));
is_callable(array(new Controller, 'staticAction'));
is_callable(array(new Controller, 'fooAction'));
is_callable(array('Controller', 'testAction'));
is_callable(array('Controller', 'staticAction'));
is_callable(array('Controller', 'fooAction'));



everything returns true except for the last call.
Shouldn't it return true as well, since the class has the magic __call method?
Or the documentation should then at least specify that is_callable only works 
with the __call method, if the first parameter of the array is an instance of 
the object
 [2012-11-22 08:01 UTC] dmitry@php.net
is_callable(array(new Controller, 'fooAction')); // call of a regular method

_call() works fine.

is_callable(array('Controller', 'fooAction')); // attempt to call a static method

__call() doesn't try to call static methods, so is_callable() returns false.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC