Bug #53765 [NEW]: $this variable doesn't get set using static reference

From: Date: Mon, 17 Jan 2011 10:51:16 +0000
Subject: Bug #53765 [NEW]: $this variable doesn't get set using static reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-157948@lists.php.net to get a copy of this message
From:             
Operating system: 
PHP version:      5.3.5
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:$this variable doesn't get set using static reference

Description:
------------
The test script output: 

Notice: Undefined variable: this

Instead $this is referenced as $instance

Attempting to do $this = $instance; returns:

Fatal error: Cannot re-assign $this

Test script:
---------------
abstract class singleton
{
final public static function getInstance()
	{
		if(null !== static::$instance){
			return static::$instance;
		}
		static::$instance = new static();
		return static::$instance;
	}
}

class myclass extends singleton
{
protected $var='foo';
public function bar()
{
echo $this->var;
}
}

$myclass = myclass::getInstance();
$myclass->bar();

Expected result:
----------------
I expected $this to hold the same value as $instance

Actual result:
--------------
Notice: Undefined variable: this

-- 
Edit bug report at http://bugs.php.net/bug.php?id=53765&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=53765&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=53765&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=53765&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=53765&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53765&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=53765&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=53765&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=53765&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=53765&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=53765&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=53765&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=53765&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=53765&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=53765&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53765&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53765&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=53765&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=53765&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=53765&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=53765&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=53765&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#157948) next »