Hi Eric (and others who might help), Actually I haven't tried the custom error handler for "function or class definiton not found errors" because I read in the manual that the processing is continued after the "statement" where the error raised. I also thought of a little hacking in php's source, but I haven't got too much experience in c. Your idea looks fine to me, but I have one question. How do you determine in the precompiler that which functions or classes are really needed? On our system it highly depends on the actual run. The template parser parses the template file, finds our special tags, and creates the appropriate objects to get the data for the tags from them. These tags and classes are nested in each other. Now while I'm writing this I have a new idea. I don't know if it will suit your needs (nor mine yet), just a quick thought. Each template classes (which gives about 50% of the whole code) are derived from one main template class (it does the hard work). The main problem is that there are many object creations in all over the code, and they depend on the actual class or template tag. So I'm trying to find a common part of the code, where I can handle the missing class definition errors, or just start over some part of the processing when an error occurs. a template example might help to understand it better: <table ...> <xarticle> <tr><td ...> <xtitle><b>{xtext}<b></xtitle> </tr></td> </xarticle> </table> The tags starting with x are our template tags (<x...> and {x...}), and each container tag (<x..>...</x..>) has it's own handler class. In <xarticle>'s handler object <xtitle>'s handler is created, which will raise an error if there's no class definition yet. If catching the "class not found errors" would work I could set a "class not found" error signal in a global variable, load the needed class in the error handler. After the error handler finished, I could check if the error signal is set in the mentioned common code and if it is I could roll back all the processing of <xtitle> and start it over this time with the already included class definition. I can relatively easily find this common code, because of the ancestor main template class, what all other template classes extend.
Because of the many roll backs this most likely wouldn't be faster than the original code was. To make things faster I could store some kind of cache for all the template files with the previously needed classes (I can get it with get_defined_classes()). This would work because the needed classes are mainly depend on the template in our system (especialy the template classes). Next time when a page is requested with the same template, I could just read the cache and include all the previously needed classes. So the sollution in general: find a common code where you can roll back to some point where the line that caused the error can be executed again. I know my example was a little complicated, but I hope you can understand it. Let me know if something isn't clear. But now I checked if I can catch the "Cannot instantiate non-existent class" error, and unfortunatelly not :(( For the developers of php: Is it hard to make this feature to work? I would really appreciate it, and would be very very happy :)) Thanks and greetings, Arpi > I have had a similar idea. I also tried the custom error handler > aproach and it didn't work here either. I have set the project > aside that I was thinking about it for but I do have some ideas > that would help and may be able to contribute. I wasn't even able > to get php to call my custom error handler for function not found > errors. How did you do that? Was there anything useful in the > context argument? My guess is that to get this aproach to work > would require hacking the code to php itself but the hack wouldn't > be very major. However I do have an alternate plan that has been > waiting for me to get around to building it is a simple parser that > will read a php file and get the required functions and classes and > then pre build a library file for just that page. The parsing > shouldn't be that dificult as all function calls begin with 'func(' > and for classes checking for 'new classname' or 'classname::' would > give me a list of all items that need to be checked for. Then > simply build (from the source) a list of all builtin php functions > and allow those and check for declarations of inline functions and > classes while parsing and remove those. That would leave a list of > functions and classes that are external. Then build a database of > classes and functions either as a real database or simple an index > of the files that contain each resource. I don't think it would be > too hard. The next step would be to make a publicly available > archive of functions and classes that fit into this index. Or to > build it into pear. > > Please keep in touch with me on this issue. Feel free to email me > off list if you want. > > Eric -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php