0

Is it possible to debug Phalcon PHP?

I'm using Sublime 3 editor but am willing to use any editor if debugging is possible.

I found a similar question on Stack Overflow but the only answer was a sales pitch about how great Phalcon is.

Updated: I'm updating this question after the fact. I learned that debugging a Phalcon application is no different than debugging a PHP application except that you cannot debug the actual Phalcon code. I didn't think it was possible to debug at all so my question might have been misleading to other developers that were new to both PHP and Phalcon at the same time.

Rich Bianco
  • 4,141
  • 3
  • 29
  • 48
  • 1
    Not sure but there are some problems currently with xdebug, phalcon 3 and php 7 if you mean this. Maybe on php 5 it can works still. Basically what can be done is extending phalcon classes - like creating proxies, override methods which you want debug and call phalcon parent class. This way you can at least debug method calls with xdebug - still you wont be able to access properties inside compiled c code of course. You can only control method calls/parameters this way - nothing more like method variable scopes inside method of phalcon extension. – Juri Sep 03 '16 at 21:23
  • After getting some answers have still not have had luck with Xdebug but from what I am reading it is difficult to make work. I am giving up on Phalcon as I could learn another language quicker than figuring out debug- am using Python which has outstanding debug capability. Phalcon is wonderful as long as you aren't the type developer that likes to do a lot of debugging. – Rich Bianco Sep 10 '16 at 03:47

3 Answers3

2

Unfortunately, since Phalcon is a compiled PHP extension, it's not possible to debug it using a PHP debugger. What we usually do to understand Phalcon internals is having a look at the Zephir source code.

Edit: since my original answer above could be misunderstood. I figured the question's goal was to debug Phalcons internal functions, which is only possible with a C debugger (as described in Luke's answer). Of course it is still possible to debug your own PHP code, but you may not step into Phalcon classes/methods.

tBureck
  • 275
  • 3
  • 10
  • 1
    Phalcon [should work with XDebug](https://docs.phalconphp.com/en/latest/reference/debug.html#using-xdebug) – Timothy Sep 05 '16 at 06:49
  • 1
    I maybe have misunderstood the question here. Clarified my answer above. – tBureck Sep 05 '16 at 13:41
  • Thank you- I did in fact misunderstand. I'm brand new to PHP and Phalcon and coming from Visual Studio and PowerBuilder was disappointed to learn that debugging wasn't possible so might be hope after all. – Rich Bianco Sep 08 '16 at 23:25
1

I'm assuming that you want to debug your PHP code, not Phalcon extension. If you mean debugging Phalcon framework itself you should install Zephir for code modifying and use gdb to run php command (at least on linux, not sure what about other systems).

Standard var_dump(), echo, printf and die

It works well with all the phalcon objects, just print out variables you want to debug using var_dump() (or other output functions) and use die() before execution your view code. If view part of application get executed will most likely replace your debug printings.

Alternatively you can also pass your variables to view part of your application and just simply use <?php var_dump($variable)?> or if you're using volt just {{dump(variable)}}.

Using XDebug Remote

This is the way I personally like the most. Yes, XDebug Remote works great with Phalcon. Personally I use NetBeans but you can use other IDE's as well. There are many tutorials for configuring all the popular IDEs so I'm not going to write it again. Note that Phalcon team suggests to use XDebug 2.2.3 or greater for better compatibility.

how to configure XDebug on PHP Storm

how to configure XDebug on NetBeans

how to configure XDebug on Sublime 3

You can read more about debuging Phalcon in Phalcon's Documentation

Community
  • 1
  • 1
Luke
  • 2,350
  • 6
  • 26
  • 41
  • This is what I was hoping for- had not debugged with PHP and I can live without debugging the compiled parts. I'm expanding the INVO sample and added a table, forms, etc., and of course it doesn't work and it's complete guess work as to why a generic error is thrown. The detailed instructions on setup are perfect- this will help myself and other new PHP'ers a lot. – Rich Bianco Sep 08 '16 at 23:29
0

The best way to debug Phalcon based application is to include below code snippet into the bootstrap section of your application AND once you get any error (application level) then you'll get very useful information like below.

  • Backtrace
  • Request
  • Server
  • Includes Files
  • Memory (this is very useful)

(new Phalcon\Debug)->listen();

Ritesh Aryal
  • 825
  • 9
  • 13