Wallogit.com
2017 © Pedro Peláez
Necessary evil
composer require axy/evil.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)
Classes are in the namespace axy\evil., (*5)
It contains calls of "evil" functions.
So how exit, echo and etc is keywords methods have other names., (*6)
Evil::execCode('2 + 2'); // 4
Evil::stop(); // exit Evil::stop(5); // exit with code 5
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)
Evil::out($message);
Sends a string to the stdout stream., (*11)
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
Static methods:, (*14)
getGLOBALS(): returns $_GLOBALS by referenceget($name [, $default]): returns the value of a global variable (or $default if the variable not found)set($name, $value): setremove($name): unset