3

I'm new to php development, so I'm probably doing something silly...

I have setup Craft running in a Vagrant VM on Windows 8. I am using XDebug and Eclipse as my IDE. It all works beautifully! However I cannot debug any of my plugin code. I can step into the Craft code but it never breaks on any plugin actions. I suspect its something to do with the way the Craft code is calling the actions, it looks like it is using some sort of reflection to call the methods of the plugin class. Can anyone help? Is there a way to debug plugin code? Or perhaps a better IDE if it is Eclipse that has this limitation?

5
  • Could this be a routing issue? Are you using {siteUrl} + config.php to correct for the right site url? What kinds of errors are you seeing? – Adam McCombs Sep 5 '14 at 4:12
  • no errors, the debugger simply doesn't break in any plugin code. The code runs but the debugger doesn't work. non plugin craft code debugs fine. – Andrew Wisener Sep 5 '14 at 11:10
  • Adam, just rereading your comment, what do you mean about using config.php to correct for right site url? I have not come across that. – Andrew Wisener Sep 6 '14 at 3:10
  • Hey Andrew - in general.php you can set dynamic urls. So in your db, you only use {siteUrl} but you can have multiple setups for your different environments. if ($_SERVER['SERVER_NAME'] == 'local.site') { return array( 'omitScriptNameInUrls' => true, 'devMode' => true, 'environmentVariables' => array( 'siteUrl' => 'local.site', 'fileSystemPath' => '', ) ); } – Adam McCombs Sep 6 '14 at 20:35
  • That is to say if this isn't set correctly or your Craft install is still pointing to your localhost vs. the server it's living on, it could cause all sorts of problems. – Adam McCombs Sep 6 '14 at 20:36
2

I can confirm that Win8.1 + PHPStorm + xDebug and plugin code works fine.

Are you symlink'ing (using mklink in Windows) to your plugin code by chance? xDebug won't follow symlink's by default and at least in PHPStorm, you have to explicitly setup the path mapping in your project's settings to tell PHPStorm/xDebug where the actual paths to your symlink'ed files live.

1
  • i dont think i'm doing that, certainly not intentionally. i wonder if its eclipse. good to know phpstorm will work – Andrew Wisener Sep 6 '14 at 23:33
1

Andrew, you could always use Whoops. https://github.com/filp/whoops.

What you could do is just install Whoops through composer in your plugin directory (here is an example of my composer.json file (http://d.pr/i/trWp).

Then you could include this within your plugin:

include(CRAFT_BASE_PATH . 'plugins/(your directory)/vendor/autoload.php');

That's basically it. Here is an example of an exception thrown within my plugin with a full stack trace.

http://d.pr/i/Ar8v

3
  • hey matt, that looks good. it seems to me that php coders much prefer dumping to the screen rather than debugging. I come from a M$ background, in visual studio .net coder not debugging is unheard of. – Andrew Wisener Sep 6 '14 at 23:32
  • Come from a .NET background as well. Give PHPStorm a go. It's by far the closest thing you'll get to VS in the PHP world. – Brad Bell Sep 6 '14 at 23:35
  • I'll second that. PHPStorm is by far the best IDE for PHP IMO. I use that along with Xdebug as well, just not for everything. I don't know the huge difference in "debugging" from the IDE and outputting most of what the IDE debugger gives you in the browser. I know with PHP you don't have to compile everything like .NET so it's probably more similar than you think. But I am not from the .NET world so I really don't know. Hope PHPStorm works well for you! – Matt Green Sep 7 '14 at 4:01
1

PHPStorm debugs fine. So the solution is to use that for debugging Craft sites

2
  • I'm using IntelliJ and can confirm debugging works on the index.php however it never comes to the breakpoint of my Plugin. How did you get this to work for PHPStorm since they are "almost" the same IDE's Thanks in advance! – IColorfield Nov 26 '15 at 21:06
  • @IColorfield: Probably worth asking as a brand new question... this is a very old thread. Feel free to link back to this thread for reference. – Lindsey D Nov 26 '15 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.