Jump to content

Recommended Posts

Hello all

 

from the PHP manual, one user comment states:

 

It wasn't quite clear, but I found out that __get() and __set() only overload attributes that _don't_ exist.

 

my question - is it possible to override this behaviour in any way so that ALL method calls can be filtered, be it using __call or otherwise?

 

I'm trying to trim out all the crap from my framework so it'd be nice to be able to see what methods never get used at all so I can better decide whether to keep them or get rid without breaking sites that currently run on it. Sure, I could write "new" versions where and how I want them and leave the old ones where they are for now, but I've got further plans - I'm working on something that (thanks to a bit of help from prozente here) will actually pull not only the required files from the framework and get them ready for distribution, but will also recreate these files with ONLY the required functions for that site. In testing on a small scale, this is working very well but if I can just filter all method calls, that'd be great.

 

Any thoughts?

Cheers

Link to comment
https://forums.phpfreaks.com/topic/47740-overloading/
Share on other sites

I doubt that's possible unless you were to extend php (work), call a logging method at the top of every method call (a headache), or use an interface method to call all other methods (very messy and breaks oh-so-many rules of oop.)

 

I figure you knew all this but just putting my 2 cents in.

Link to comment
https://forums.phpfreaks.com/topic/47740-overloading/#findComment-235027
Share on other sites

Ne pas possbile ou le overloading methods.. :P

 

How about using the backtrace? Write a basic logging class that uses DOM (or simpleXML), ReflectionClass and the backtrace to create an XML file. Whenever a class is used in the execution, it - and methods not in the BT - gets added to the tree. Whenever a method gets used, it's get dumped from the tree.

 

After testing all application features, you should end up with a file listing all unused methods. If you also want unused classes you'll have to traverse the file system.

 

Probably the best point to call this procedure is from the destructor of your frontcontroller or better yet indexcontroller if you use one (which you probably do).

Link to comment
https://forums.phpfreaks.com/topic/47740-overloading/#findComment-235081
Share on other sites

genericnumber1, yeah i did consider logging each method but some of them are literally only a line or two long as they are, and the resources used in another function call would have probably made it a bit sluggish. I also considered (as it's a long term solution not just a short term clean up thing) renaming all my methods with a prefix (so they wouldnt be recognised at all by apps using them) and running them ALL through a __call method, but again I'd guess this would be quite sluggish. As for extending PHP, I wouldnt know where to start.

 

I've looked also at a few debuggers that seem like they might do the job, but really this kinda does need to be integrated into the framework rather than extensions or other tools.

 

John - yeah I have both an index and front controller, so I guess no issues implementing something like that, just that I find the backtrace quite limited for uses such as this in that it doesnt backtrace that far. I guess I could give it a go on a smaller part and see how it goes...even if it doesnt work, I'll prob still pick up a few useful tricks along the way...:)

 

Thanks both

Mark

Link to comment
https://forums.phpfreaks.com/topic/47740-overloading/#findComment-235093
Share on other sites

I can think of one thing that will work, but it's not exactly elegant.. :-\

 

1) Create a copy of your framework.

2) Loop though all files in the copy framework, after each method declaration insert a call to the method logger.

3) In the same loop have the method logger populate the XML file with all methods.

3) Test run the copy extensively, have the method logger move (to a new document) or remove used methods.

 

You can use regex to modify the files, this old thread of mine might help:

 

http://www.phpfreaks.com/forums/index.php/topic,114708.0.html

 

 

Link to comment
https://forums.phpfreaks.com/topic/47740-overloading/#findComment-235441
Share on other sites

you mean actually "manipulate" and insert logging code on the fly? (read the php file, add the code, rewrite it). yeah i guess that could work, as i currently have ability to seperate the framework into "production" and "development" versions, so i guess nothing wrong with extending this further...

 

i'll let you know how it goes. cheers!

Link to comment
https://forums.phpfreaks.com/topic/47740-overloading/#findComment-235475
Share on other sites

Mark, I think what Jenk is trying to say is that besides listing methods, you can also get the starting line of method's declaration using Reflection.

 

So if you insert a new line with the call to the logger after the declaration, it should work without regex.

 

Tbh I hadn't thought of that, but it should work.

Link to comment
https://forums.phpfreaks.com/topic/47740-overloading/#findComment-235746
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.