php – How to know where the script stopped? – Education Career Blog

I was wondering if there was a way to know where the script stopped (ie: file + line), which would be useful for debugging or for removing stupid ‘exit’ calls lost somewhere in the code.

Thanks in advance

,

Wrong (and I’m sorry for not testing it first): You could use register_shutdown_function in conjunction with debug_backtrace.

See here for a duplicate of your question: Fastest way to determine where PHP script exits .

,

If you want to remove exit from the script, try using PHP Code Sniffer PEAR package http://pear.php.net/package/PHP_CodeSniffer

Just create a sniffer to find out where all the exits are in the code (you get a report of file and line).

If you want to find out what line a script stopped at, use a debugger and you can get a stack trace to find out the last line a script executed too (Xdebug is easy to use and set up). Any debugger is going to severely hinder performance as it needs to manage more memory.

,

I’m not sure what IDE your using (if any), but this would be trivial using xdebug. I personally use it with netbeans and it works great although it is a bit tricky to setup. It will let you walk through your code step by step and show exactly where it is exiting.

Leave a Comment