|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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) {
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 11:00:02 2025 UTC |
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.