PHP Classes

File: vendor/phpcsstandards/phpcsextra/Universal/Docs/CodeAnalysis/ForeachUniqueAssignmentStandard.xml

Recommend this page to a friend!
  Classes of Adeleye Ayodeji   Download Installed Plugin   vendor/phpcsstandards/phpcsextra/Universal/Docs/CodeAnalysis/ForeachUniqueAssignmentStandard.xml   Download  
File: vendor/phpcsstandards/phpcsextra/Universal/Docs/CodeAnalysis/ForeachUniqueAssignmentStandard.xml
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Download Installed Plugin
Download a WordPress plugin as a ZIP archive
Author: By
Last change:
Date: Yesterday
Size: 1,047 bytes
 

Contents

Class file image Download
<?xml version="1.0"?> <documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" title="Foreach Unique Assignment" > <standard> <![CDATA[ When a foreach control structure uses the same variable for both the $key as well as the $value assignment, the key will be disregarded and be inaccessible and the variable will contain the value. Mix in reference assignments and the behaviour becomes even more unpredictable. This is a coding error. Either use unique variables for the key and the value or don't assign the key. ]]> </standard> <code_comparison> <code title="Valid: using unique variables."> <![CDATA[ foreach ($array as $k => $v ) {} ]]> </code> <code title="Invalid: using the same variable for both the key as well as the value."> <![CDATA[ foreach ($array as $k => $k ) {} ]]> </code> </code_comparison> </documentation>