note 58583 added to function.is-callable

From: Date: Tue, 08 Nov 2005 20:41:17 +0000
Subject: note 58583 added to function.is-callable
Groups: php.notes 
Request: Send a blank email to php-notes+get-98274@lists.php.net to get a copy of this message
To corey at eyewantmedia dot com: your misunderstanding lies in passing in the naked $object parameter. It is correct for is_callable to return FALSE since you cannot 'call an object', you can only call one of its methods, but you don't specify which one. Hence: is_callable(array($object, 'some_function'), [true or false], $callable_name) will yield the correct result. Notice, though, that a quick test I made (PHP 5.0.4) showed that is_callable incorrectly returns TRUE also if you specify the name of a protected/private method from outside of the context of the defining class, so, as wasti dot redl at gmx dot net pointed out, reflection is the way to go if you want to take visibility into account (which you should for true OOP, IMHO). ---- Manual Page -- http://www.php.net/manual/en/function.is-callable.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58583 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58583&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58583&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58583&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58583&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58583&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58583&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58583&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58583&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#98274) next »