Renaming a PSR Namespace Directory in PhpStorm 2017.1

When you rename a directory that is also part of a PSR-0/4 namespace structure, PhpStorm 2017.1.4 will now rename your namespace to match.

PSR-0 and PSR-4 are a direct 1:1 mapping between namespace levels and folders. Consequently, when you rename a PSR-0/4 directory, you then need to go and change all the namespaces for classes in that folder, to match the new directory structure. Now PhpStorm 2017.1.4 will do the work for you.


This will work only if you’ve marked your directory as a sources root and have informed PhpStorm what the namespace prefix of the sources root is. Find out more about marking directories in this video.

This will work for all files in the renamed directory, plus any sub-folder with files in them, so you can be sure that all your namespaces will be correct when you’ve updated a namespace by renaming the directory.

– Gary & The PhpStorm Team

About Gary Hockin

Gary Hockin has been creating code to power web applications for 15 years, the last three of them at an extraordinary level. He is handsome, talented, funny and articulate, and also extremely modest. Gary is a valued contributor to Zend Framework 2 and is a member of the community review team. He's married and has two wonderful children, and when he's not coding, writing about code, speaking about code or reading about code, he can usually be found in the pub playing pool.
This entry was posted in Cool Feature, Newsletter. Bookmark the permalink.