rspec/rules/S2651/php/rule.adoc

71 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
In PHP 5.4, ``++break++`` and ``++continue++`` no longer accept arguments that require computation. Static arguments are still okay except for zero (``++0++``).
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2021-04-28 16:49:39 +02:00
----
$i = 0;
$break = 1;
while (++$i) {
switch ($i) {
case 5:
// ...
break $break; // Noncompliant
case 10:
// ...
break $break + 1; // Noncompliant
default:
break $break; // Noncompliant
}
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2021-04-28 16:49:39 +02:00
----
$i = 0;
while (++$i) {
switch ($i) {
case 5:
// ...
break 1;
case 10:
// ...
break 2;
default:
break;
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* Remove the variable argument to "xxx".
* "0" is not a valid argument to "xxx"
'''
== Comments And Links
(visible only on this page)
=== on 27 Feb 2015, 17:09:12 Ann Campbell wrote:
source: https://twitter.com/declaassen/status/571237732548087808[twitter]
=== on 19 May 2015, 15:55:05 Linda Martin wrote:
OK!
endif::env-github,rspecator-view[]