0

I recently started web development. The course I took was to install WAMP and start developing right away. I used an atom text editor, this -combined with wamp- proved to be a very fast way to write client-side code(HTML, CSS, Javascript).

But when I started to write serverside PHP things got a little messy. I should probably explain my site's structure here.

I keep separate PHP, CSS, javascript files for every page on the client side, for the server side a have 2 different types of PHP files:

  1. Files that only perform a specific operation on the database(For example returning "5 more answers"). These are always called by AJAX requests.

  2. Files that load the page for the first time. These are only used when the user opens the page for the first time, they do necessary database queries and return the page. Later requests always go to the 1st type of PHP files.

Now regarding my problem. I debugged until now by printing variables to the screen with var_dump() or echoing. But this started to become too slow as the data I work with grew. I wonder if there is a way of debugging which will let me but a breakpoint in one of my PHP files. Then, when I open it on the browser, on the localhost I created using WAMP, will let me go through the PHP file step by step.

I have been dealing with this issue for 3 days, I tried to make it work with Eclipse IDE but couldn't find a way. Also, there seems to be no tutorials or Q&A on the internet regarding the issue.

Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28
Rookie
  • 175
  • 1
  • 4
  • 19
  • You need the xdebug extension installed and an IDE that supports it. Not sure if Eclipse or Atom do, but NetBeans and PHPStorm do. See [here](https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html). – Alex Howansky Jan 03 '19 at 14:12
  • Do you know [XDebug](https://wiki.eclipse.org/Debugging_using_XDebug)? If not, installing and using XDebug would be a first step. – fvu Jan 03 '19 at 14:13
  • @fvu It comes installed with WAMP. – Rookie Jan 03 '19 at 14:19
  • @AlexHowansky I will take a look at the NetBeans and PHPStorm. I'm looking for open-source IDE's even if I can get a student's licence for PHPStorm. – Rookie Jan 03 '19 at 14:21
  • 1
    To be completely honest, I've never used xdebug but have learnt more from `not` using it rather than relying fully on xdebug. I have to admit, without using error reporting you'll never learn PHP properly, so I would suggest enabling all error reporting modes: https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display However, if you feel the need you can't do without debugging tools, I would suggest something like this for Atom: https://atom.io/packages/php-debug – BRO_THOM Jan 03 '19 at 14:23
  • @HalilKaragöz agree, but that 1) doesn't enable it in Eclipse nor 2) tells us that OP is aware of its existence. – fvu Jan 03 '19 at 14:47
  • @BRO_THOM I actually did try php-debug plug-in for Atom. But couldn't get it to work. There is just not a good tutorial I guess. Do you have any helpful links regarding this solution, because that would be the best solution for me. – Rookie Jan 03 '19 at 17:45

3 Answers3

1

Breakpoint debugging opens a whole new world, and is the natural step after var_dump() debugging. Not only does it speed up development, but it provides much more information about your code, as you can step through each line and see what values have been set at each step, and how they evolve as your program executes its code. This means you can track the entirety of the values at different stages with one run - imagine tracking all variables at each point using var_dump()!

Although choosing an IDE is a personal decision based on personal taste, i strongly recommend you try out PhpStorm. If you can get a student licence go for it.

PhpStorm has extensive documentation & tutorials on all features in the IDE, debugging is no exception:

https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html

https://www.youtube.com/watch?v=GokeXqI93x8

leuquim
  • 636
  • 6
  • 16
0

I don't know of a specific solution to your issue. I'm not exactly sure what you're doing but as a quick tip, I find add the following snippet to the top of the file useful as it will highly error more easily rather than browser just say nope.

error_reporting(E_ALL);
ini_set('display_errors', 'On');

Hope this help you a bit.

  • I'm currently debugging like this. What I want is actually check my query results without printing them everytime. I'm also planning to make image processing stuff later on so viewing and manipulating variables is a big deal for me. Thanks anyways. – Rookie Jan 03 '19 at 17:42
  • I'm sorry I think i'm out of my depth on this question, I don't understand how you can check results without seeing the results. For me debugging or checking query output is a matter of knowing the expected results and then see what I expect. To me this is a fundamental part of unit testing. – Alexander Ingham Jan 04 '19 at 10:24
0

I tried out what's recommended in comments and answers. I first tried Netbeans. To be fair it disappointed me. Download kept getting stuck at 100%, even for different versions. When I stopped downloading and went ahead to create a php project, there was missing parts I guess. I couldn't even manage to create a php project. But that might just be me not being able to do it.

Then I followed @leuquim's answer and @Alex Howansky's comment and downloaded PHPStorm. And I got it to work in no more than 20 minutes. I downloaded it with a student's licence. For people who want to use PHPStorm with WAMP here's a Youtube tutorial:

https://www.youtube.com/watch?v=CxX4vnZFbZU

One thing to note in the video is that, maker of the video chooses PHP Web Application in the Run Configurations. That has been changed to PHP Web Page.

Rookie
  • 175
  • 1
  • 4
  • 19