PHP find out where die was used - php

I've got some quite complicated php website and after some changes I'm getting 'white screen of death', I'm pretty sure its some die; exectued somewhere.
Is there any way to show file and line of code where die; was executed?
[edit]
To response answers here - it's not about finding all dies in entire project. It's about showing witch one was used during some specific execution. It's becouse sometimes (usually with frameworks like mvc) it's not so easy to know what php files were used.

Your IDE supports text search as others already pointed out. As an alternative, use grep. A command like grep -rnwI die * in the root of your source folder would help you along a bit.
Also, if you haven't done so already, enable error_reporting and display_errors. That way you won't have to guess whether a die(); or exit; is still there.

Just configure your project in any IDE like Netbeans or Eclipse and then you can use the FIND feature inside it .
Simply search for "die" then IDE will let you know all the files having words "die" along with their line numbers.
Hope it helps...

use some of the tools like netbeans press ctrl+F to search the value in your project

Related

PhpStorm does not recognize PHP

I saw many different questions here, but nothing was helpful to me.
I have no trouble with an interpreter, I tried to reset PhpStorm's cache.
It looks like file functions.php isn't accessible.
I really don't want to make a total reset. Maybe somebody has an idea how to solve it?
I'm not sure what I actually did and how to reproduce this issue again, but now it works well. I took previous version of PHPstorm. When I installed new one, the previous one was simply renamed to sth like 'phpstorm2'.
Here are my thoughts what actually happened:
As I understand for highlighting is responsible that part of application which is managed under Languages & Frameworks / PHP / PHP Runtime.
To reproduce this issue you may try to disable there "Core / Core" and try to write down in any place of your phpfile following:
\Exception::class();
And in your case this class will not be highlighted, as it presents in Core_c.php. In my case it is placed in
/opt/phpstorm/plugins/php/lib/php.jar!/stubs/Core/Core_c.php
I'm 100% sure that these libs were always enabled, but why I didn't saw this - that is the question.
So if I face this issue again my steps would be:
Try to verify Languages & Frameworks / PHP / PHP Runtime. The better way would be to enable ALL libs.
Check External Libraries in the project tree. Check read privileges for /opt/phpstorm/plugins/php/lib/php.jar and probably reinstall this plugin.
Try to find out function which I don't actually see in External Libraries.

Why notepad++ autocomplete doesn't work with function arguments?

I checked "Settings > Prefences > Backup/Auto-Completion > Enable Auto-completion on each input" and "Function parameters hint on input" options. I have Notepad++ 5.9 (unicode) version. It auto completes function names but not their arguments. Also i tried re-install. I know it has this feature but not working. Any idea why?
I mean it auto completes print_r when i write "pri" but i want it to work like in the image;
http://i51.tinypic.com/3322auc.jpg
Hmm, this is not an answer to your question but I want to share it anyway.
I have used Notepad++ for years. I didn't like Eclipse and NetBeans is just so damn slow.
I never used the auto complete function for anything.
Notepad++ can't really do any code analysis, it can only give you auto-completion on the known PHP functions.
I've since switched to an IDE that does full code analysis and can do auto-completion for your own code as well.
Notepad++ is great if you just want to write something real quick. It's also a great tool if you want to learn about PHP since it doesn't do auto-completion very well ;) but if you really want to be productive when you're working on a large application I recommend you use an IDE that does code analysis. Productivity is the key here. I spend less time looking through files and more time actually writing code, which is great! :D
Good IDEs for PHP: NetBeans, PHPStorm, Eclipse.
For this feature to work, you need to supply an .xml file which contains the appropriate functions and parameters.
An example for Javascript with installation instructions can be found here.
I have not yet found xml files for PHP (or Python, which I'm looking for). But it seems this can work in npp, you just need to locate the right xml file.
Best of luck!
(Oh, and don't listen to the naysayers who are too quick to give up, npp works fine as an IDE.)
Notepad++ it's very good text editor, but it's not IDE.
Try to use IDE - NetBeans or PhpStorm, and you will get much more than just smart autocomplete.
I have a same question about this, function hint is Ok,but param hints not display until I download a new release of notepad++(a not install release), all is ok. before, I tryed many time, and edit the xml files.
If you will edit you own language, Can copy from a exist language xml ,for cpp.xml in plugins/APIs folder. It's easy to understand its rule.
It is very easy to have a error, if you config file is changed.

php searching question

I have a lot of php code and I'm going through it right now (500+ files). I was hoping to find a program that would let me easily search through the files to see which files contain a specific variable I am editing. Kind of like a super edit -> find from notepad++. Anyone have any suggestions?
Best,
Pavan
One word. ack.
You can also try Agent Ransack
You can use a PHP ide such as NetBeans or your alternative is if you want to stick with notepad++ you can the Find in files which is located in the last tab when you hit CTRL+F
using NetBeans IDE you can lay your project out into a really decent code profiler and be able to see what your code is doing from a visual prospective.

How to know where the script stopped?

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.

Best Practices for locating a function definition in PHP

Is there a simple way to find the file path to where a function is defined? I currently use dreamweavers FIND in an entire directory. Would be nice to have something that doesn't require downloading the entire site tho.
Any suggestions?
Personally I use an IDE like Netbeans or Eclipse PDT. In the case of Netbeans you can ctrl-click on a function and it'll take you to the definition. Sometimes there is a choice in which case it'll make you select one.
But its generally bad form to reuse a function name within your code in different files. It can lead to hard-to-find bugs because it's hard for any program to figure out exactly which one function is actually getting called since source files can be included dynamically.
Would be nice to have something that doesnt require downloading the entire site tho.
I hope this doesn't mean that you're modifying the site remotely.
Have a local working copy, make the changes, test them locally, then upload the changes.
A simple combo of vim and ctags makes the "go to definition" task a piece of cake.
You can't search for something (and expect to find it) unless you have a copy of all the files it might be in.
A number of IDEs have the ability to click and go from a use of a variable or function to its definition. If not that, then a multi-file searching tool within your editor, or something from a command line (such as ack) that is a little more specialised at searching source code can help. Good naming conventions can also help a lot for consistency.
It's not the question, but why don't you have a copy of the site locally - and while you are at it, keep it in version control as well?
I'd sure like this get_functionPath() ability and anyone that has extensively had to work on other people's code would probably find it incredibly useful. We have function_exists, if that could simply return the file the function is defined in for user defined functions it would save a TON of trouble. No, not all of us use IDEs, and yes some of us have been doing this long enough to code on the production machine. Test boxes and sandboxes are for rookies.
One trick is to purposely trigger an error in the function you are trying to locate. Can save a ton of time.
You'd need to use some kind of tool that could build an index on a remote filesystem that you could download and perform local lookup and search upon. I don't know of anything that can do this and a few moments with Google didn't turn up anything.
Maybe a good idea for an open source project? hinthint
so there is no function that would do this? Something like get_class() which would output the parent class but in the case the file path on the server...

Categories