- requires version 2016.2 (currently EAP)
- Xdebug only enabled when needed, means Composer, unit tests etc. will be much faster
See also my (regularly updated) PhpStorm Xdebug troubleshooting post.
This is a common problem – the error is in Illuminate/Container/Container.php (line 736 or 741).
Common reason: spaces in environment variable values in .env file
Two other fixes that have worked for me:
'production' === env('APP_ENV')
in a ternary operator in config/app.php was the solution.
Updated Fri 7 Dec 2018.
Running Xdebug remotely is very useful – you can add breakpoints, inspect and modify the state of all variables/objects and type PHP code into a live console. No need to manual add var_dump() statements etc.
It should save you a lot of time.
Unfortunately, while the setup should be straightforward, it’s easy to lose the programming time you save spending ages tweaking your Xdebug and PhpStorm configuration to get it to work in the first place. (In fact, I don’t think it’s worked correctly first time for me once.)
Also, you’ve probably got multiple projects, maybe running on different VMs, or using Docker (scroll down for special instructions for Docker on the Mac).
To enable/disable Xdebug:
Uncomment the zend xdebug extension and turn on remote_enable
zend_extension=xdebug.so xdebug.remote_enable = 1
Restart Apache – via one of:
/Applications/DevDesktop/apache/bin/apachectl -k restart
To turn on xdebug, make sure you’ve got:
installed_extras: [...] - xdebug
vagrant provision to build/rebuild (this won’t affect your site). Leave PhpStorm set to port 9000.
On other installations, here’s my growing checklist when I try to use Xdebug and nothing happens:
(The following is based on Xdebug 2.4.0RC4 and PhpStorm 2016.2.1)
Step 1: you should identify whether it’s a complete lack of communication between Xdebug and the IDE, or if PhpStorm is receiving the data the data but is setup wrong.
Close and restart PhpStorm. Make sure PhpStorm is listening for PHP Debug Connections (bottom of Run menu, or green telephone icon top right), then reload your app in the browser.
What you’re looking for is either:
a) an ‘Incoming connection’ dialog the very first time you open a webpage of your app.
b) ‘Debug session was finished without being paused” in the Event Log.
Either of these confirms Xdebug is talking to PhpStorm and you can need not worry about your php.ini entries, the possibility you’re using the wrong port or that you forgot to trigger the bookmarklet – goto section B.
If nothing happened at all, go to section A.
wt$ sudo lsof -i :9001 Password: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME phpstorm 80592 wt 330u IPv4 0xaad56de5076720c3 0t0 TCP *:etlservicemgr (LISTEN)
If PhpStorm is not listening this will be blank.
Note: you might want to set the PHP_IDE_CONFIG environment variable on your server. This tells PhpStorm which path mapping configuration it should use so it doesn’t prompt you. It needs to be written like this:
my-server.dev must match the name configured in Languages & Frameworks > PHP > Servers – as shown below:
Go to: Run > Web Server Debug Validation (instructions here)
Your Docker containers will have an IP address beginning 172.xxx.xxx.xxx (each container gets it’s own – check what it is) You might assume that’d be enough to avoid conflicts with your real IP address or 127.0.0.1 when specifying xdebug.remote_host.
Note: on macOS, you need to create a symlink to your IP otherwise PhpStorm won’t be able to hear Xdebug.
sudo ifconfig lo0 alias 10.254.254.254
Restart everything and things should start working.
This is a fairly crucial bit of object-oriented PHP, but I only found out about it today after x years, so it’s bound to trip someone else up.
Essentially, if you want to copy some values from an object, doing this is a very bad idea:
$a = new A;
$b = $a;
…because it’s not like copying a variable (passing it by value) where $a and $b are independent, $b is just a pointer to $a. So this:
…will remove foo from $a as well.
Wiser programmers than me may well be saying, “Why do you need to copy an object anyway?”, and indeed I can’t remember doing so before.
I needed it’s properties, so I could write a record of an API call to a logfile (but minus sensitive info like the API keys). These were indeed removed from the log, unfortunately all the REST calls stopped working and it took a while to realise why. get_object_vars (which chucks the properties in an array and leaves the original object intact) was what I should have used.
Note objects are passed as pointers, not as references, as explained in great detail here (read the comments.)
I wrote this StackOverflow answer, explaining how you can safely backup your work, destroy the old PHP 5.6 Vagrant box and download a brand new one that comes with PHP 7 as standard.
In my opinion this will be easier and cleaner for most people than trying to perform an in-place upgrade (the exception is where you’ve extensively customised PHP, MySQL or Nginx, in which case you need to backup the appropriate config files too.)
There are also some notes on the format of Homestead.yaml when you have more than one site, as the documentation on shared folders isn’t terribly clear.
IdeaVim is a popular plugin that adds vim shortcuts (e.g. hjkl navigation) to PhpStorm and similar products.
A rare bug Mac users may replicate one day: it’s possible to accidentally disable IdeaVim by pressing cmd-alt-V – the same shortcut as moving files in Finder. PhpStorm does need to have focus; in my case I was typing the standard copy/paste/move shortcuts to transfer some files in the Project window.
You can see/toggle the Vim status with Tools > Vim Emulator (which won’t show up as a search result if you use shift-cmd-A and type ‘ideavim’). It’s a handy shortcut to be aware of – temporarily turning Vim off may make it easier to complete certain refactoring tasks where you’re entering a new variable name.
IdeaVim’s settings are in vim_settings.xml in the WebIde100 folder (where the 100 at the end indicates version 10.0.*), in the event of a problem you can inspect or trash that file.