rspec/rules/S1765/php/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

59 lines
1.6 KiB
Plaintext

== Why is this an issue?
The `var` keyword in PHP was historically used to declare class properties with default public visibility.
However, its usage is discouraged as it lacks clarity and explicit visibility declaration.
Instead, PHP introduced the keywords `public`, `protected`, and `private` to clearly define the visibility of class properties.
This enhances code readability and maintainability, as it becomes easier to understand and control access to class members.
Additionally, using the keywords for explicit visibility helps prevent unintended modifications or security vulnerabilities that may arise from the ambiguity of the `var` keyword.
=== Noncompliant code example
[source,php,diff-id=1,diff-type=noncompliant]
----
<?php
class Foo
{
var $bar = 1;
}
----
=== Compliant solution
[source,php,diff-id=1,diff-type=compliant]
----
<?php
class Foo
{
public $bar = 1;
}
----
== Resources
=== Documentation
* https://www.php.net/manual/en/language.oop5.visibility.php[PHP Manual - Visibility]
* https://www.w3schools.com/php/keyword_var.asp#:~:text=The%20var%20keyword%20creates%20a,public%20should%20be%20used%20instead[W3Schools - var Keyword]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace the "var" keyword with the modifier "public".
'''
== Comments And Links
(visible only on this page)
=== on 27 May 2014, 20:01:53 Ann Campbell wrote:
The reference I found has a slightly different reading on the deprecation: \http://www.php.net/manual/en/language.oop5.properties.php
endif::env-github,rspecator-view[]