From:
Operating system: Irrelevant
PHP version: 5.3.5
Package: *General Issues
Bug Type: Bug
Bug description:Presence of __invoke makes protected __construct visible as
callable
Description:
------------
Presence of __invoke causes is_callable($obj, '__construct') returns true,
instead of false when it's called out of class scope.
Also, is_callable('class', '__construct') yields true even if __construct
is set
to protected (which is clearly not connected with __invoke issue, but I
suppose
that is caused by the same underlying problem).
Although setting __construct private/protected seems a little bit pervert,
if it
is not interdicted by language semantics, visibility testing should give
good
results.
Test script:
---------------
class Singleton {
protected static $aInstances = array();
final protected function __construct(){}
public static function getInstance(){
$sClassName = get_called_class();
if (!isset(static::$aInstances[$sClassName])) {
static::$aInstances[$sClassName] = new
$sClassName();
} // if
return static::$aInstances[$sClassName];
} // getInstance
} // class
class SingletonWithInvoke extends Singleton {
final protected function __invoke(){}
} // class
var_dump(is_callable(Singleton::getInstance(), '__construct'));
var_dump(is_callable(SingletonWithInvoke::getInstance(),
'__construct'));
var_dump(is_callable('Singleton', '__construct'));
var_dump(is_callable('SingletonWithInvoke', '__construct'));
Expected result:
----------------
bool(false) bool(false) bool(false) bool(false)
Actual result:
--------------
bool(false) bool(true) bool(true) bool(true)
--
Edit bug report at http://bugs.php.net/bug.php?id=53683&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=53683&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=53683&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=53683&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=53683&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=53683&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=53683&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=53683&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=53683&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=53683&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=53683&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=53683&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=53683&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=53683&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=53683&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53683&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53683&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=53683&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=53683&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=53683&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=53683&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=53683&r=mysqlcfg