Search code examples
phpphpstorm

PhpStorm autocomplete new file and class not work


When I create new file in PhpStorm, it does not complete anything and the page is blank.

For example, when I create a class named Database it should create a file with this ready code

 <?php


class Database{


}

but nothing happened and the page is empty.


Solution

  • I assume you are talking about code templates. In such case I recommend you to visit JetBrains help page and ensure that you have your templates installed correctly.

    Please, check your template and see, if it is set like this:

    PHPStorm tempate If you have it setup correctly, you should be able to see a prompt for a class name and namespace, please, fill out the form and PHPStorm will generate the file for you. If it does set correctly, try to reinstall the software.

    Please, check if you are using actual version of PHPStorm and have a license for it.

    If none of this will help, use menu Help -> New Support Request. JetBrains has a very good support team.

    UPDATE1:

    PHP Class template

    <?php
    #parse("PHP File Header.php")
    
    #if (${NAMESPACE})
    
    namespace ${NAMESPACE};
    #end
    
    class ${NAME} 
    {
    
    }
    

    Now switch to Includes tab. There should be template like this enter image description here

    PHP File Header.php template content (file name and extension must match the one from #parse() directive):

    /**
     * ${PROJECT_NAME}
     * ${FILE_NAME}
     *
     * PHP Version 5
     *
     * @category Production
     * @package  Default
     * @date     ${DATE} ${TIME}
     * @license  http://${PROJECT_NAME}.com/license.txt ${PROJECT_NAME} License
     * @version  GIT: 1.0
     * @link     http://${PROJECT_NAME}.com/
     */
    

    I recommend you to reinstall PHPStorm, it should have those templates.