how load_class function works? |
[eluser]djuric[/eluser]
ok this function is defined in Common.php and it's used throughout the system. When defining this function, there is code like: Code: if ( ! function_exists('load_class')) There is 'passing by reference' sign here, at function definition: Code: function &load;_class() { // function } And also, each time when this function is called, it's called with this same reference sign Code: $BM =& load_class('Benchmark', 'core'); I read somewhere about this, but I don't really understand how codeigniter benefits from this. So if can anyone tell me more about usage of this, I would greatly appreciate it ![]()
[eluser]djuric[/eluser]
This is probably php documentation for this http://www.php.net/manual/en/language.re...return.php It says: "Returning by reference is useful when you want to use a function to find to which variable a reference should be bound. Do not use return-by-reference to increase performance. The engine will automatically optimize this on its own. Only return references when you have a valid technical reason to do so" What's the valid technical reason %-P
[eluser]Aken[/eluser]
When classes are loaded, they are stored into the static $_classes array. If you use load_class() on a class that is already loaded, the function finds the already-loaded class in that array, and then passes it back by reference. This means that any time that class is loaded to a variable, every variable will be a reference to the same class instance. Then, if changes are made to any variable, the changes will be available across the script. http://www.php.net/manual/en/language.references.php
|
Welcome Guest, Not a member yet? Register Sign In |