Bug #53765 [Fbk->NoF]: $this variable doesn't get set using static reference
| From: | php-bugs at lists dot php dot net | Date: | Mon, 18 Feb 2013 00:34:39 +0000 |
| Subject: | Bug #53765 [Fbk->NoF]: $this variable doesn't get set using static reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-176950@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53765&edit=1
ID: 53765
Updated by: php-bugs@lists.php.net
Reported by: jon dot skarpeteig at gmail dot com
Summary: $this variable doesn't get set using static reference
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.3.5
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2011-01-17 18:23:28] cataphract@php.net
I can't reproduce with this:
<?php
abstract class singleton {
protected static $instance = null;
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();
echoes "foo". Is this the correct script?
------------------------------------------------------------------------
[2011-01-17 11:56:06] jon dot skarpeteig at gmail dot com
* correction:
abstract class singleton
{
protected static $instance = null;
final public static function getInstance()
{
if(null !== static::$instance){
return static::$instance;
}
static::$instance = new static();
return static::$instance;
}
}
and:
var_dump($this); - not echo
------------------------------------------------------------------------
[2011-01-17 11:51:16] jon dot skarpeteig at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=53765&edit=1