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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: olympic at dino-online dot de
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC