• 8

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

PHPstorm - Unable to set breakpoints in blade.php files

I'm working on a Laravel application and can debug my controller php files fine, but Id like to also debug the blade.php files. With my current setup Ive followed all of jetbrains recommend settings for Laravel, (https://confluence.jetbrains.com/display/PhpStorm/Laravel+Development+using+PhpStorm#LaravelDevelopmentusingPhpStorm-DebuggingLaravelApplicationswithPhpStorm) but it is still not allowing my to set breakpoints in the blade.php files.

What could I be missing?

      • 2
    • In what file -- original .blade.php or compiled blade file? You definitely cannot set it in original one -- because it's not executed.
      • 1
    • Thanks for the fast response, I didnt know that it was compiled and generated separately. Yes I am referring to the original blade.php file. Whats the best way to debug php variables in the compiled files then?
      • 1
    • I think PhpStorm has some issues with debugging actual compiled blade files (due to the way how files got named and how IDE works: such files have no extension and IDE is unable to associate them with PHP files file type in order to be able to place breakpoints etc). Please refer to this ticket: youtrack.jetbrains.com/issue/WI-25835
    • The blade syntax cannot be evaluated by the debugger (because the interpreter is implemented in Laravel). While PHPStorm does offer support for Blade templating to a certain extent, it cannot place breakpoins inside a blade.php file unless the code is within .

Putting a

<?php xdebug_break(); ?>

into your blade file works pretty well. Even in my tests, PHPstorm jumps to the next PHP statement in some cases.

Why this works:

Laravel processes the blade file to a normal PHP file in the cache folder. But the PHP statement xdebug_break(); will be transferred there and cause the program to halt at the position you want it to (in the cache file).

  • 73
Reply Report
      • 1
    • This same trick works in XDebug, using any IDE that supports it. I'm using it with UltraEdit Studio, although it should work in your favorite IDE, even my least favorite, Eclipse.

To close this question - phpstorm doesnt support this functionality at the moment. A work around provided by jetbrains support was to add *.blade.php to file type associations under PHP in the IDE settings, however, it still wasnt working for me after doing this.

It appears that they created a youtrack ticket in response to my request, if youd like to encourage jetbrains to work on this please upvote: youtrack.jetbrains.com/issue/WI-26476

  • 3
Reply Report

Even if you can get the IDE to enable breakpoints on the blade files, it won't work - Laravel composes a PHP file from the Blade file - it is this file that is eventually used when the script is run - not the Blade file.

A Work-Around

This works for PHPStorm - but something similar might be possible in other IDEs.

Laravel (5) stores the composed files under storage/framework/views. These files have random generated file names - so it may be tricky to find the file you want. An easy way is to delete all these temp files and then refresh the page you want to debug. A new file will be created. In PHPstorm you can right-click on the file and select the file's extension type. (Not sure about other IDEs)

You will now be able to set breakpoints. Obviously you will need to make the changes in the Blade file - but this will at least help you to figure out what is wrong.

**Update: Alex's solution is easier! **

  • 2
Reply Report

I devised an even better hack, which allows conditional debugging support, so that you aren't stuck with XDebug_break for the rest of eternity.

The single line expands as follows.

<?php if ( \app\utils\DebugLogger::EnableForBlades ( ) ) xdebug_break ( ) ; ?>

This statement has a couple of unusual features.

  1. Since blade files done't have use directives, the method name, \app\utils\DebugLogger::EnableForBlades is fully qualified.
  2. Since blade files seem to lack support for the usual code blocking mechanism, the one-line statement is devoid of braces, and is terminated by a semicolon.

EnableForBlades is a static method that queries an environment variable (one of those defined in .local.env), returning True if that variable evaluates to True. Otherwise, it returns False, and xdebug_break is suppressed.

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions