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?
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).
Go to your Jetbrains IDE Settings (Ctrl+Alt+S; ⌘+,; etc.)
Languages & Frameworks > PHP > Debug > Tempates
Enter in Blade Debug > Cache path: \path\to\app\storage\framework\views
Enjoy
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
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! **
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.
Since blade files done't have use directives, the method name, \app\utils\DebugLogger::EnableForBlades is fully qualified.
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.
Related
I've taken over a code base of a Symfony 4.4-project, with a couple of extra bundles installed (Sonata being the biggest one). When I write: php bin/console list, then it prints the source code for several of the classes in the src/Admin-directory. And I can't figure out why.
I've searched the code for print, var_dump and dump, but can't figure out where this is.
I'm not familiar enough with Symfony, to go through the code 'from the top', adding my own dump-statements, narrowing it down, where this code is coming from.
Had this been Laravel, then I would have started in the routes, then moved on to maybe the kernel or middleware, then to the controlles - and in the end the views.
Does anyone have a good suggestion on which files to add dump-statements to, to see where this code is coming from?
... Or if anyone else has a good idea on how to find this code, then I'm all ears.
Is it maybe an entire namespace that is printed? And can one even do that?! Hmm...
This is what it looks like:
You'll get this behavior if the code you've inherited uses short open tags <? but your personal dev environment's PHP installation has them disabled. Run php --ini to find where your ini file is and then edit that to change from this:
short_open_tag = Off
To this:
short_open_tag = On
Alternatively, you could edit all the source files and change the short open tags <? to long open tags <?php.
I'm trying to migrate from PHP Storm to VS Code but there's a little issue that is bothering me.
I'm using PHP Intellisense (tryied Intelliphense too), configured it as the instructions asked (I Have PHP 7.2 and PATH set correctly), my project was opened as a folder.
So here's whats going on (examples):
require('incs/DB.php');
$con=new DB(configs,goes,here);
DB included and configured to use. If I try to type: "$con->" suggestions appear as they should (GREAT!)
Now another file:
index.php
require("config.php");
...more code...
If in this file I try to type "$con->" nothing that matters shows up. The suggestions have nothing to do with the class "$con" is using.
So, did I make something wrong or is this a common thing in the extension? Can I only call for suggestions on the same file that "created" the class?
This used to work, but it stopped working recently. I don't think anything changed in my settings, but I have poured over them for a couple hours now just to make sure. I have checked all over google and SO too. Please pay attention to the details before claiming "this was answered over here..." Thanks. :)
Assumptions and Requirements
Assume we have two files:
<project_root>/index.php
<project_root>/folder/file.php
Assume our project root is /home/me/project.
We want to include file.php from index.php. We expect PhpStorm to be able to resolve the file path and allow us to do nifty IDE things like "Go To Declaration."
What works
require 'folder/file.php';
require '/home/me/project/folder/file.php';
$root = '/home/me/project/';
require $root.'folder/file.php';
What No Longer Works
define('ROOT_DIR', "/home/me/project/");
require ROOT_DIR.'folder/file.php';
PhpStorm does recognize the value of ROOT_DIR when I mouseover, but it highlights home and says something like: Path '"/home/me...folder/file.php' not found
Why Use a Constant Anyway?
To keep this simple, I've left out details that are not necessary to illustrate the problem. The primary thing I'd like to address is why this used to work but no longer does, and/or how can I make it work again.
Sorry, can't help. What are you really trying to do?
Here are the details I left out. If we can't solve the primary issue, perhaps we can find a good work around.
I'm working with an existing codebase. Most files require a config.php file that defines root_dir() for getting the web/project root. PhpStorm wasn't resolving those paths (understandably so), so I created a constant to takes it's place. That makes more sense anyway.
In today's battle, I discovered that you can do this:
/** #define "root_dir()" "/home/me/project/" */
// or
/** #define "ROOT_DIR" "/home/me/project/" */
If you put that anywhere in the file then PhpStorm is able to resolve all the includes/requires in that file. BUT, it only works in that file, even if you try to include/require it in another file. You'd have to do this to EVERY file to get it working everywhere. Nope. Nuh-uh. No thank you. I need to reference the absolute path to the project/web root in a way that PhpStorm will recognize across the whole project.
#LazyOne answered this in the comments. This is a bug in the latest release, and it's being tracked here: https://youtrack.jetbrains.com/issue/WI-31754
Until this gets patched I've created this work around:
Using Keyboard Maestro, I created a hotkey that will paste the #define comment at the top of the file and return the cursor to its original position. Download the macro here. Import that and edit the text.
Edit: You may actually need to edit the file in a regular text editor. One of the file paths may need to be changed to work on your system.
Note: I'm using a modified version of the Mac Eclipse keyboard layout in PHPStorm. I'm not sure that will matter.
Also, be aware that many of your "changed files" will simply have this mapping at the top of the file, and this mapping may not be correct for you teammates. I'm simply excluding those changes from my commits.
I have set up PhpStorm 5 with PHPUnit, and I'm curious if PhpStorm might have some functionality that will automatically run a unit test when saving a file. Like watchr and guard. I have tried search our beloved www and the PhpStorm docs, but haven't been able to find a solution for it.
As of version 6, PHPStorm has "File Watchers"
Open your project preferences.
Select File Watchers from the left hand list of options.
Click the + symbol at the bottom of the empty right hand panel.
Select <custom>
You will have to set up a command line for PHPUnit, it wont be the integrated testing, but you can have errors output to the console (which is good a good start!)
Various macro options are available to you, so you can include (for example) $FileNameWithoutExtension$Test.php in the arguments passed to your command line.
I personally had to set up two watchers. The first detected modifications to project files, and the second detected changes to test files (the second did not append Test.php to the filename) I also created a new project scope to exclude the tests directories from the first watcher.
You may also want to turn off immediate synchronisation, as this causes PHPUnit to run when PHPStorm auto-saves files.
My other settings are like:
File Type: PHP files (PHP)
Scope: Project excluding tests
Program: /path/to/php
Arguments: /path/to/phpunit --configuration /path/to/phpunit.xml.dist /path/to/tests/$FileNameWithoutExtension$Test.php
Working directory: $FileDir$
Output paths: $FileDir$
No output filters set, syntax error checks enabled, and console showing errors.
PHPUnit watcher named as hot phpunit runner
https://github.com/slavahatnuke/hot-phpunit-runner
You can also have a look at TDDRunner
It is console tool that execute PHPUnit autmaticly on file changes. You can also configure PHPUnit by excuting only one file ot whatever.
/usr/bin/tddrunner --group=test
There's a a German article providing further detail.
In 2017 Jetbrains release a feature that allow auto-run for tests.
It's located in the Run console, therefore it's linked to the run settings, easing the setup of this autorun.
See https://blog.jetbrains.com/phpstorm/2017/07/autorun-phpunit-tests-in-phpstorm-2017-2/
I'm migrating a php application from procedural to oop.
I use a DEBUG constant to activate errors and warnings output (in fact, I have thee, every one makes the output more verbose.
But I can't find a way to access those constants from within a method.
The constants are defined before autoload in a separate file.
In the utility file I have
define('DEBUG', TRUE);
And inside a given method I tried to
if(!defined('DEBUG')) define('DEBUG', FALSE);
But I always end up with DEBUG=FALSE.
What am I doing wrong? I'm a total noob to oop, so be gentle please :-)
Clarification
Every class has his own file.
In any given script, the first thing I do is to include the utility file. The utility file is the one who defines DEBUG and has the _autoload function.
script_file.php
includes utility_file.php
defines DEBUG
has _autoload function
according to this, you should access DEBUG (no prepending $) in your code directly. are you including or requiring your utility file in the same file that has the function you're talking about? i don't think this is an OOP problem
darkphoenix was right, This wasn't an OOP problem. This was a NetBeans problem.
I'm using NetBeand and uploading the files to a remote server upon save. I've set the DEBUG constant to TRUE in the utility file and hit save on NetBeans, the save process (apparently) went without problems (no warnings or anything).
Big was my surprise when latter I logged in via SSH did a cat on the file. The file was never saved to the server. My local copy has my last edit, but the remote one doesn't...
Moral of the story: I hate you NetBeans