PhpStorm 2021.1 Help

Code Inspection: Implicit type conversion



This inspection checks for any implicit conversions between the predefined XPath-types STRING, NUMBER, BOOLEAN and NODESET. While this is usually not a problem as the conversions are well-defined by the standard, this inspection can help to write XSLT scripts that are more expressive about types and can even help to avoid subtle bugs:

<xsl:if test="foo" /> is not the same as <xsl:if test="string(foo)" />

The first test checks whether the element "foo" exists (count(foo) > 0), the latter one however is only true if the element actually contains any text (string-length(foo) > 0). The plugin will then offer to make the type-conversion more explicit.

There are several options to adjust the inspection to personal preferences by offering the possibility to individually enable it for implicit conversions between certain types.


The plugin can also be told to always flag explicit conversions that do not result in the actually expected type, such as <xsl:if test="number(foo)" /> and provides a special option to ignore the conversion from NODESET to BOOLEAN by using the string() function as a shortcut for writing string-length() > 0.

Powered by XPathView + XSLT-Support

Suppress an inspection in the editor

  1. Position the caret at the highlighted line and press Alt+Enter or click the Intention action icon.

  2. Click the arrow next to the inspection you want to suppress and select the necessary suppress action.

Last modified: 16 July 2021