php - Pass object by reference or value -


i'm sure question has been asked thousand times, had trouble finding answer understand or use anywhere.

in project, need use sql class , other misc classes, in alot of classes. i'm qurious know what's best way performance wise pass objects.

should pass objects classes construct reference?

class myclass {     private $_link;      function __construct(&$db) {         $this->_link =& $db;     } } 

or value..

class myclass {     private $_link;      function __construct($db) {         $this->_link = $db;     } } 

or create new object?

class myclass {     private $_link;      function __construct() {         $this->_link = new db();     } } 

if using php5+, in cases, objects passed reference default.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -