2017 © Pedro Peláez
 

library evil

Necessary evil

image

axy/evil

Necessary evil

  • Friday, January 12, 2018
  • by axy
  • Repository
  • 1 Watchers
  • 0 Stars
  • 376 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

axy\evil

Latest Stable Version Minimum PHP Version Build Status Coverage Status License, (*1)

  • The library does not require any dependencies.
  • Tested on PHP 5.4+, PHP 7, HHVM (on Linux), PHP 5.5 (on Windows).
  • Install: composer require axy/evil.
  • License: MIT.

Documentation

Some language features are not recommended for frequent use. eval(), exit, global variables, direct access to super-global arrays., (*2)

But sometimes it is necessary. If you use static code analyzer, it will swear. We'll have to suppress messages., (*3)

/** @SuppressWarnings(PHPMD.Superglobals) */
$x = $_POST['x'];

This library encapsulates the "evil" features. You simply call methods and disclaims any sin., (*4)

API

Classes are in the namespace axy\evil., (*5)

Evil

It contains calls of "evil" functions. So how exit, echo and etc is keywords methods have other names., (*6)

eval - execCode
Evil::execCode('2 + 2'); // 4
exit - stop
Evil::stop(); // exit
Evil::stop(5); // exit with code 5
breakpoint()
breakpoint(mixed $message [, bool $line [, bool $file [, int $status]);

Shows debugging information and terminates the current script (with the status from $status)., (*7)

If $message is not a scalar then used print_r()., (*8)

If specified $line: shows the line number of the breakpoint. For $file shows the file name., (*9)

Evil::breakpoint('point'); // point
Evil::breakpoint('point', true); // 15: point
Evil::breakpoint('point', true, true); // /path/to/script.php:15: point

In CLI mode the $message completes new line. In HTTP mode the $message enclosed in <pre>., (*10)

echo - out
Evil::out($message);

Sends a string to the stdout stream., (*11)

Superglobals

Static methods of axy\evil\Superglobals:, (*12)

  • getSERVER()
  • getGET()
  • getPOST()
  • getREQUEST()
  • getCOOKIE()
  • getFILES()
  • getSESSION()
  • getENV()

Return the corresponding superglobals arrays. The data is returned by reference., (*13)

$session = Superglobals::getSESSION();
$session['var'] = 'value'; // no effect

$session = &Supeglobals::getSESSION();
$session['var'] = 'value'; // success

Globals

Static methods:, (*14)

  • getGLOBALS(): returns $_GLOBALS by reference
  • get($name [, $default]): returns the value of a global variable (or $default if the variable not found)
  • set($name, $value): set
  • remove($name): unset

The Versions

12/01 2018

dev-master

9999999-dev https://github.com/axypro/evil

Necessary evil

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

10/11 2015

0.1.0

0.1.0.0 https://github.com/axypro/evil

Necessary evil

  Sources   Download

MIT

The Requires

  • php >=5.4.0