From:             pacha dot shevaev at gmail dot com
Operating system: windows
PHP version:      5.1.0RC1
PHP Bug Type:     Scripting Engine problem
Bug description:  Fatal error: Cannot re-assign $this(again)

Description:
------------
PHP 5.1RC1 throws fatal error when some variable gets assigned with $this
by reference. However there's a workaround for this fatal error which is
very simple: using a helper function which simply returns the passed
argument by reference. I'm a bit lost here - what is the expected
behavior?

Yes, it may seem a bit weird to assign objects by reference in PHP5 but if
you keep your code base PHP4 compatible you know what i mean. 

Reproduce code:
---------------
<?php

function & getRef(&$ref) {
  return $ref;
}

class Foo {
  function Foo() {
    //$ref =& getRef($this); //works just fine
    $ref =& $this; //throws "cannot re-assign $this" fatal
    $ref->test();
  }

  function test() {
    echo 'test';
  }
}

$foo = new Foo();

?>

Expected result:
----------------
test

Actual result:
--------------
Fatal error: Cannot re-assign $this

-- 
Edit bug report at http://bugs.php.net/?id=34358&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34358&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34358&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34358&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34358&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34358&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34358&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34358&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34358&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34358&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34358&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=34358&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=34358&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34358&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34358&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34358&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34358&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34358&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34358&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34358&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34358&r=mysqlcfg

Reply via email to