php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #20216 is_callable needs documentation
Submitted: 2002-11-01 16:53 UTC Modified: 2003-07-18 02:04 UTC
From: leon at leonatkinson dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4CVS-2002-11-01 OS: RH 7.3
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: leon at leonatkinson dot com
New email:
PHP Version: OS:

 

 [2002-11-01 16:53 UTC] leon at leonatkinson dot com
Please add a description of is_callable to the documentation.  Here are some rough notes about how what this function does.

This function wraps zend_is_callable.  The first argument is the name of a function or method.  Class an object methods are specified by passing an array with two elements: class or object and method name.

The second argument seems to be for checking syntax only, but I can't figure out how to make is_callable return FALSE when the second argument is TRUE.

The third argument receives the "callable name".  In the example below it's "a::b".  Note, however, that despite the implication that a::b() is a callable static method, this is not the case.

<?
	class a
	{
		var $c;
		
		function b()
		{
			return($this->c);
		}
	}

	$d = new a;

	if(is_callable(array($d, 'b'), FALSE, $name))
	{
		print($name);
	}

?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-18 02:01 UTC] philip@php.net
This is now (almost) documented and can be seen here:

http://cvs.php.net/co.php/phpdoc/en/reference/var/functions/is-callable.xml

It's currently commented out as I'm not comfortable with these docs or this topic.  Please provide some more feedback :)
 [2002-11-18 15:14 UTC] leon at leonatkinson dot com
OK, here's some additional information about the function that should be enough for writing documentation.

When the second argument is true, the function only checks that the value passed for the first argument follows the correct format.  That is, it's either a string or an array with two elements.  If an array, a check is made that the first element is a string or an object and the second element is a string.  In this mode, no check is made for the existence of the function.

The third argument receives a description of the function meant for the user to read.  The description isn't implying anything about a method being callable statically.  (In fact, on this point, this might be my own imagination and not something anyone else would guess.)

Here's a reasonable example of use.

<?
    function callIfPossible($f)
    {
        if(is_callable($f, FALSE, $callName))
        {
            call_user_func($f);
        }
        else
        {
            print("Unable to call $callName<br>");
        }
    }

    function a()
    {
        print('function a<br>');
    }

    class c
    {
        function m()
        {
            print('method m<br>');
        }
    }


    callIfPossible('a');
    callIfPossible('b');
    callIfPossible(array('c', 'm'));
    callIfPossible(array('d', 'm'));
?>
 [2003-07-18 02:04 UTC] philip@php.net
Someone documented this a couple weeks ago, it'll show up when the manual is next built.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 22:01:28 2025 UTC