php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39209 virtual self
Submitted: 2006-10-20 09:35 UTC Modified: 2006-10-20 09:52 UTC
From: dtyschenko at soft-ukraine dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.1.6 OS: Any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dtyschenko at soft-ukraine dot com
New email:
PHP Version: OS:

 

 [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?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-20 09:46 UTC] tony2001@php.net
This is not a forum, use lists for discussions.
 [2006-10-20 09:52 UTC] dtyschenko at soft-ukraine dot com
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
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 21 10:00:02 2025 UTC