php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33537 assignment of $this to another var
Submitted: 2005-07-01 17:47 UTC Modified: 2005-07-01 18:41 UTC
From: bo at theaddedones dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2005-07-01 (dev) OS: OSX
Private report: No CVE-ID: None
 [2005-07-01 17:47 UTC] bo at theaddedones dot com
Description:
------------
i can understand this error from inside a class

class Foo{
  function bar(){
    $this =& $something_else;
  }
}

but i should think one can assign a ref to $this to another var.
class Foo{
  function bar(){
    $this_dupe =& $this; //fails to compile
    $this_dupe = $this; //compiles okay
  }
}
 
the reason i bring this up, is in php4 and 5.0 this is allowed .. if code needs to run on php4 without silly performance hits (i.e. data copy on assignment), would be nice to keep that.

from the error it seems it is trying to do this
$this =& $this_dupe .. but that is not what is being done


Reproduce code:
---------------
<?php
class Foo{
  function bar(){
    $this_dupe =& $this; //fails to compile
    $this_dupe = $this; //works a okay
  }
}

Expected result:
----------------
hopefully it should compile fine

Actual result:
--------------
Fatal error: Cannot re-assign $this in {test.php} on line 4


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-01 18:41 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC