Wrapper around features of PHP which affect global scope

v2.0.0 2015-02-04 16:57 UTC


This library provides object-oriented wrappers around some of the features of PHP affecting global scope.

The currently implemented features are:

  • Constants
  • Functions
  • Echo / Print

Global state is evil. Avoid it wherever possible. Do not think this library makes it okay.

This library has two main use cases:

  • when you're working in an environment where it's unavoidable, and you still want code you write as testable as possible
  • while you're refactoring your code to get out of this mess


Install it with composer, adamquaile/php-global-abstraction.



$constants = new \AdamQuaile\PhpGlobal\Constants\ConstantWrapper();

$constants->set('key', 'value');



$functions = new \AdamQuaile\PhpGlobal\Functions\FunctionWrapper(
    new FunctionCreator(),
    new FunctionInvoker()

# Create function with a specified name

$functions->create($callable, 'func_in_global_scope');

# Create function and return its automatically generated name

$functionName = $functions->create($callable);

# Call a function existing in global scope
$functions->invoke('strlen', 'hello world');

Echo / Print


$output = new \AdamQuaile\PhpGlobal\Output\EchoWrapper();

$output->output('Hello ', $world);