Bug #60428 [Opn->Wfx]: $this as byref
| From: | johannes@php.net | Date: | Fri, 10 Feb 2012 23:42:57 +0000 |
| Subject: | Bug #60428 [Opn->Wfx]: $this as byref | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167413@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60428&edit=1
ID: 60428
Updated by: johannes@php.net
Reported by: bjorn at hcbmedia dot nl
Summary: $this as byref
-Status: Open
+Status: Wont fix
Type: Bug
Package: *General Issues
Operating System: Any
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
This is caused by different optimisations for access to $this we have. The only way we could detect
this is by preventing to pass $this by reference, which isn't a good restriction in the
language. Afterwards, in your ref method we have no way to figure out that $this was passed.
Therefore we all have to live with this.
Previous Comments:
------------------------------------------------------------------------
[2011-12-01 15:01:29] bjorn at hcbmedia dot nl
Description:
------------
take a look at the following script
<?php
class B {
public $b = 50;
public function whoami () {
var_dump (__CLASS__);
}
}
class A {
public $a = 6;
function thisref () {
var_dump ($this); // A
$this->ref ($this); // exchange $this by a B object
var_dump ($this); // B
var_dump ($this->a); // 6
var_dump ($this->b); // Notice: Undefined property: A::$b
var_dump (isset ($this->a)); // true
var_dump (property_exists ($this, "a")); // false
var_dump (__CLASS__); // A
$this->whoami (); // A
var_dump ($this instanceof self ? "A" : "B"); // B
}
function ref (A &$ref) {
$ref = new B();
}
public function whoami () {
var_dump (__CLASS__);
}
}
$a = new A();
$a->thisref ();
?>
it supplies $this variable as a property to a byref function, then changing it to a diffrent type.
if gives some strange results
Expected result:
----------------
it should not be possible to supply $this as a byref param
Actual result:
--------------
$this seems to be changed, however any call upon $this seems not, so properties and methods remain
unchanged.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60428&edit=1