php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33397 Passing cass variable by reference makes variable become reference
Submitted: 2005-06-19 06:57 UTC Modified: 2005-06-25 05:08 UTC
From: nikolaeff at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.11 OS: Linux
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: nikolaeff at gmail dot com
New email:
PHP Version: OS:

 

 [2005-06-19 06:57 UTC] nikolaeff at gmail dot com
Description:
------------
Guess that $site->config shouldn't became reference after it passed to method by reference. Am i right ?


Reproduce code:
---------------
class Config {}

class Database {
    function Database(&$config) {} /* here */
}

class Site {
    var $config;
    var $db;
    function Site() {
        $this->config = new Config();
        /* turns $this->config to a reference: */
        $this->db     = new Database($this->config); 
    }
}

$site = new Site();
var_dump($site);


Expected result:
----------------
object(site)(2) {
  ["config"]=>
  object(config)(0) {
  }
  ["db"]=>
  object(database)(0) {
  }
}


Actual result:
--------------
object(site)(2) {
  ["config"]=>
  &object(config)(0) {
  }
  ["db"]=>
  object(database)(0) {
  }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-19 13:52 UTC] sniper@php.net
No, you're wrong.

 [2005-06-25 05:08 UTC] nikolaeff at gmail dot com
So tell me please, why i should write:

function Site() {
    $config = new Config();
    $this->db     = new Database($config); 
    $this->config = $config;
}

instead of:

function Site() {
    $this->config = new Config();
    $this->db     = new Database($this->config);
}

???

If it's a feature i'd like to see where it's documented.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC