PhpStorm 2023.3 Help

Code Inspection: Implicit type conversion

Reports implicit conversions between the predefined XPath-types STRING, NUMBER, BOOLEAN, and NODESET. Helps to write XSLT scripts that are more expressive about types and prevents subtle bugs:

Example:

<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). Suggests making the type conversion more explicit.

Use the following options to configure the inspection:

  • Enable or disable implicit conversions between certain types

  • Always report explicit conversions that do not result in the actually expected type, for example, <xsl:if test="number(foo)" />

  • Ignore conversion from NODESET to BOOLEAN by using the string() function as a shortcut for writing string-length() > 0.

Suppress an inspection in the editor

  1. Place 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: 25 March 2024