![]() |
Object *RECURSION* is a Bug? and the Solution - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Object *RECURSION* is a Bug? and the Solution (/showthread.php?tid=19644) |
Object *RECURSION* is a Bug? and the Solution - El Forum - 06-14-2009 [eluser]Unknown[/eluser] First sorry my poor english... When I try to debug using print_r($this) I have strange output that I think it should be bug. but for sure I posted it here... here is my code: Code: <?php Here's my result ( the "...." indicate that i strip some of the output ) Code: Bugtest Object So, is it right or wrong? I'm not expert but I think even if the *RECURSION* happen because reference to the real object. it still need a lot of heavy steps before PHP assume it was recursion. I suspect 3 files that caused that problem the files are: - Session.php * - Encrypt.php ** - Model.php *** Problem * --------- For Session.php, the Session class has attribute $CI and in constructor it was assigned using Code: $this->CI =& get_intance(); Solution * ---------- remove $CI attribute, and use only Code: $CI =& get_instance() Problem ** ---------- Same as Session.php, in Encrypt.php it has $CI attribute and assigned Code: $this->CI =& get_instance(); Solution ** ----------- Just remove $CI attribute from the class and remove line Code: $this->CI =& get_instance(); .... CONTINUE TO NEXT POST .... Object *RECURSION* is a Bug? and the Solution - El Forum - 06-14-2009 [eluser]Unknown[/eluser] Problem *** ----------- On Model.php, the recursion only appear when you assign another name to the Model. The routine check in failed to determine wheter the new model name is instance of the original Model. Take a look at these code: Code: function _assign_libraries($use_reference = TRUE) Solution *** ------------ Code: function _assign_libraries($use_reference = TRUE) Instead of hacking the original file, replace the original wine by putting it on application/libraries. Suggestion or comments are welcome... Thanks. Object *RECURSION* is a Bug? and the Solution - El Forum - 01-18-2010 [eluser]macigniter[/eluser] So let's say I have a huge library with lots of functions. Do you think it would be better in regards to performace to get the CI instance in every function via Code: $CI =& get_instance(); instead of assigning the instance to a class variable like Code: $this->CI =& get_instance(); and risking the *RECURSION* in lots of other objects? EDIT: I just did a benchmark with the CI output profiler and couldn't find any difference in loading speed or file size. So I guess it doesn't really matter? Object *RECURSION* is a Bug? and the Solution - El Forum - 01-18-2010 [eluser]Phil Sturgeon[/eluser] There is no recursion, they are using refferences so the values are only ever stored once. This is not a bug at all, part of normal PHP behavior. Basically, do not output $this. :-) Object *RECURSION* is a Bug? and the Solution - El Forum - 01-18-2010 [eluser]macigniter[/eluser] [quote author="Phil Sturgeon" date="1263833586"]Basically, do not output $this. :-)[/quote] Hehe ![]() |