Edit report at http://bugs.php.net/bug.php?id=53683&edit=1

 ID:                 53683
 Updated by:         fel...@php.net
 Reported by:        tomasz dot slominski at gmail dot com
 Summary:            Presence of __invoke makes protected __construct
                     visible as callable
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            *General Issues
 Operating System:   Irrelevant
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

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

See your code, you are using is_callable('foo', 'bar') instead of
is_callable(array('foo', 'bar'))... :)


Previous Comments:
------------------------------------------------------------------------
[2011-01-07 01:02:09] tomasz dot slominski at gmail dot com

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 this bug report at http://bugs.php.net/bug.php?id=53683&edit=1

Reply via email to