rspec/rules/S2036/php/rule.adoc

50 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Files that define symbols such as classes and variables may be included into many files. Simply performing that inclusion should have no effect on those files other than declaring new symbols. For instance, a file containing a class definition should not also contain side-effects such as ``++print++`` statements that will be evaluated automatically on inclusion. Logic should be segregated into symbol-only files and side-effect-only files. The type of operation which is not allowed in a symbol-definition file includes but is not limited to:
* generating output
* modifying ``++ini++`` settings
* emitting errors or exceptions
* modifying global or static variables
* reading/writing files
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
<?php
print "Include worked!";
class foo {
// ...
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
<?php
class foo {
public function log() {
print "Include worked!";
}
}
----
2021-04-28 16:49:39 +02:00
== See
* https://www.php-fig.org/psr/psr-1/[PHP-FIG Basic Coding Standard PSR1], 2.3 - Side Effects
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]