|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-01-28 22:33 UTC] felipe@php.net
-Status: Open
+Status: Bogus
[2011-01-28 22:33 UTC] felipe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 20:00:02 2025 UTC |
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)