ID: 39209
User updated by: dtyschenko at soft-ukraine dot com
Reported By: dtyschenko at soft-ukraine dot com
Status: Bogus
Bug Type: *General Issues
Operating System: Any
PHP Version: 5.1.6
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2006-10-20 09:46:34] [EMAIL PROTECTED]
This is not a forum, use lists for discussions.
------------------------------------------------------------------------
[2006-10-20 09:35:43] 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?
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39209&edit=1