Tracking where method is beeing called |
[eluser]Unknown[/eluser]
Hello, We are having a problem here at work. We are a developer team and we are working at some project. Today i need to change a method at some Models. The problem is,i have no idea where it's beeing used. So i am afraid to change it, and break some one else code. My question is, there is any kind of debuging that allow me to track it? I want to know where this function is beeing used. Thank you.
[eluser]Sudz[/eluser]
Hi, You can use Code: debug_backtrace() For example, suppose your function name is test, use below code Code: function test( ) It will print the details from where the test method is being called.
[eluser]hyperfire[/eluser]
Easy! 1) Enable log on your index.php 2) Load the url helper 3) Put this on your model: Code: log_message('info', 'The methox #INSERT METHOD NAME# was called by ' . current_url()); Let the app run for few hours/day. Download the log and search for your info message.
[eluser]Unknown[/eluser]
Tks for the reply. But is not that,what i am looking for. I will try give an example. Code: function test1() { I have the function test1 being called at function test2 and function test4. So i need some code to tell me that. That is what i need. Tks once again.
[eluser]Otemu[/eluser]
Hi, Some things come to mind: Certain IDE's allow for you to search for functions so maybe investigate that. Just var_dump(debug_backtrace()); in your function, every time that function is called your know where it coming from Can you not just do a simple find in all files for the function "test1();"? Hope that helps
[eluser]TheFuzzy0ne[/eluser]
Debugging is not the solution. Searching files is. By debugging, you can't be sure you've covered every single occurrence of a call to that method. With searching files you can be pretty sure you've covered every avenue. All you need is a good file search app. I recommend [url="http://www.mythicsoft.com/page.aspx?page=download&type=agentransack"]Agent Ransack[/url]. It's just awesome. As a fail-safe, you can keep the old method name and use it as an alias for the new method name. This is untested, but might help. Code: function __call($method, $args) With a bit of luck, your log file should remain empty, but if it doesn't, you should be able to locate any offending code. Probably not the DRYest example, but since you'll be phasing it out anyway, I don't think it should be an issue. You just need to copy this into each model where you're changing method names, and adjust the map accordingly. If you wanted to, you could put this into your MY_Model class, and move the map out so it becomes a property of your model, but I think that might be overkill, since you won't be using it on all of your models.
[eluser]boltsabre[/eluser]
Quote:The problem is, i have no idea where it’s beeing used.Well, it sounds like the development team is not documenting things correctly! However, even if you have good documentation all it takes is one person not to update it and it's useless for your particular situation. Another thing that comes to mind is that you (not you personally, but your development group as a whole) have been making the functions too big and too complex. This is a classic example of code smell/stink!!! http://en.wikipedia.org/wiki/Code_smell http://c2.com/cgi/wiki?CodeSmell A good function should only do one thing and do it good!!! If it's doing more than one thing it should be called "I_am_a_piece_of_code_that_if_gets_changed_may_break_my_app_because_I_am_being_used_for_multiple_purposes_and_no_one_really_knows_anymore_what_my_purpose_is" . But as per what TheFuzzyOne said, the only real way to track down all uses of it is to do a search of the entire code base. |
Welcome Guest, Not a member yet? Register Sign In |