Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2036

Files that define symbols should not cause side-effects

    XMLWordPrintable

    Details

    • Message:
      Refactor this file to either declare symbols or cause side effects, but not both.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Covered Languages:
      PHP
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • PHP-FIG:
      1-2.3

      Description

      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

      Noncompliant Code Example

      <?php
      
      print "Include worked!";
      
      class foo {
        // ...
      }
      

      Compliant Solution

      <?php
      
      class foo {
        
        public function log() {
          print "Include worked!";
        }
      
      }
      

      See

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: