|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-10-20 09:35 UTC] dtyschenko at soft-ukraine dot com
Description: ------------ As I know all functions in PHP are virtual. This mean that $this always is type of object, but self is type of class where function is called. So when I try to execute new self, it's creating instance of class where function was executed. Maybe self should be something like virtual too? PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 18:00:01 2025 UTC |
Sorry, I will explain: <?php abstract class aSingleton { private static $_instance; private final function __construct() {} public final static function getInstance() { if (!self::$_instance) { self::$_instance = new self; } return self::$_instance; } public final function __clone() { throw new Exception('denied'); } } class cStorage extends aSingleton { } $obj = cStorage::getInstance(); ?> Fatal error: Cannot instantiate abstract class aSingleton in /var/www/html/autosave/cStorage.php on line 8 Why self is of class aSingleton when I call it as cStorage::getInstance(); Should be of class cStorage