rspec/rules/S1765/php/rule.adoc

52 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
The PHP 4 method of declaring a variable, using the ``++var++`` keyword, was deprecated in early versions of PHP 5. Even though it's not considered deprecated in the most recent versions, it's nonetheless not best practice to use it. When ``++var++`` does appear, it is interpreted as a synonym for ``++public++`` and treated as such. Therefore ``++public++`` should be used instead.
From the PHP Manual:
____
The PHP 4 method of declaring a variable with the var keyword is still supported for compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT warning.
____
=== 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
----
<?php
class Foo
{
var $bar = 1;
}
----
=== 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
----
<?php
class Foo
{
public $bar = 1;
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]