Early Access Program

PhpStorm 2021.1 EAP #6

In this build, we’re adding support for prefixed table names in SQL queries. Read on to learn more.

The Early Access Program is coming to a close, and we are now focusing on stabilizing and polishing PhpStorm for the release. This is a good time to report any lingering issues that you’ve encountered to our tracker as there is still time to fix them before release.

Check out the What’s Coming in PhpStorm 2021.1 video, which also covers things not mentioned in this blog post, on the JetBrains YouTube channel.

Download PhpStorm 2021.1 EAP

Support for prefixed table names in SQL

Many content management systems and frameworks allow you to specify a table prefix. This can be useful, for example, if you’re using the same database for multiple different applications.

In previous versions, PhpStorm would lose database integration in such cases because SQL queries contained markers for prefixes.

With PhpStorm 2021.1, it will be possible to specify prefixes in the .phpstorm.meta.php file. If you are not familiar with meta files, check out our help article on the topic.

Let’s say we have the following query in a Drupal app:

You’ll notice how PhpStorm is unable to resolve either the table name or the columns. That’s because we have specified a table prefix in the Drupal config.

To fix this, add a .phpstorm.meta.php file anywhere in the project with the following content:

namespace PHPSTORM_META {
    // Virtual function to indicate that all SQL
    // injections will have the following replacement rules.
      '{' => "PS2021_", // all `{` in injected SQL strings will be replaced with a prefix
      '}' => '',        // all `}` will be replaced with an empty string

Note how we specified a prefix replacement here.

With this file, PhpStorm will be able to link SQL queries to data sources and provide you with all its smart features, such as completion, resolve, and so on.

This works with concatenation as well. See the following example:

const DB_PREFIX = "mydatabase_"; 
$sql = "SELECT * FROM " . DB_PREFIX . 'table_name';

Extensions in the `suggest` section of composer.json now considered

Your codebase may have classes from PHP extensions. Previously, PhpStorm checked if such extensions were added in the `require` section.

However, extensions may sometimes be optional and the existence of the classes from the `suggest` section may be checked for before usage.

In v2021.1, PhpStorm will consider extensions in both `require` and `suggest` sections.

When an extension is registered in `composer.json` as suggested but is used without checks, like extension_loaded() or function_exists(), then PhpStorm will warn you about this. You can use a quick-fix to move extensions to `require/require-dev`.

The full list of changes in this build is available in the release notes.

  • Important! PhpStorm EAP builds are not fully tested and may be unstable.
  • You can install an EAP build side by side with a stable PhpStorm version to try out the latest features.
  • EAP builds are free to use but expire 30 days after the build date.

Please report any problems you find to our issue tracker or by commenting on this post.

Your JetBrains PhpStorm team
The Drive to Develop

image description