#33397 [Bgs]: Passing cass variable by reference makes variable become reference

From: Date: Sat, 25 Jun 2005 03:08:42 +0000
Subject: #33397 [Bgs]: Passing cass variable by reference makes variable become reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-80996@lists.php.net to get a copy of this message
ID: 33397 User updated by: nikolaeff at gmail dot com Reported By: nikolaeff at gmail dot com Status: Bogus Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 4.3.11 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2005-06-19 13:52:54] sniper@php.net No, you're wrong. ------------------------------------------------------------------------ [2005-06-19 06:57:11] 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) { } } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33397&edit=1

« previous php.bugs (#80996) next »