php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35034 $this != ($this)
Submitted: 2005-10-31 12:00 UTC Modified: 2005-11-01 17:51 UTC
From: olympic at dino-online dot de Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.0.5 OS: *nix
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 - 7 = ?
Subscribe to this entry?

 
 [2005-10-31 12:00 UTC] olympic at dino-online dot de
Description:
------------
$this is treated as references, while ($this) not...

$this != ($this) ?? omg :)


Reproduce code:
---------------
error_reporting(E_ALL);

class Bar {
        function onlyByRefPlease(&$foo) {
// ...
        }
        function        someMemberFunc1() {
                $this->onlyByRefPlease($this);
        }
        function        someMemberFunc2() {
                $this->onlyByRefPlease(($this)); // note: 2 Braces!
        }
};

$foo = new Bar();
$foo->someMemberFunc1();
$foo->someMemberFunc2(); // throws error


Expected result:
----------------
/* none */

Actual result:
--------------
Fatal error: Only variables can be passed by reference in /www/v3.evalanche.com/web/php_refbug.php on line 13

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-31 12:58 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

($this) is an expression, not a variable, thus you can not pass it by reference.
 [2005-11-01 17:51 UTC] olympic at dino-online dot de
Following your comment:

$a=new Foo();
$b=$a ; // $b references $a
$c=($a); //$c is now a copy because only variables
are referencable ? (NOPE)

Well, seems a little bitte inconsistent for me, why
different behaviours in assignment and method calls ?
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 17:05:44 2022 UTC