PHP Classes

Persistent PHP Superglobals Array Maker: Create array variables that act like superglobals

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 134 All time: 9,199 This week: 192Up
Version License PHP version Categories
globals-maker 1.0The PHP License5PHP 5, Data types
Description Author

This package can create array variables that act like superglobals.

It can initialize arrays of variables that are accessible from different functions.

The package can also merge an array with an existing superglobal variable.

Innovation Award
PHP Programming Innovation award nominee
June 2018
Number 6
Superglobals are variables that can be accessed from any function in PHP code, being those global functions or functions of class.

PHP provides several built-in superglobal variables for different purposes.

This package can implement custom superglobals that any application can create and use just like the built-in superglobal variables.

Manuel Lemos
Picture of zinsou A.A.E.Mo´se
  Performance   Level  
Name: zinsou A.A.E.Mo´se is available for providing paid consulting. Contact zinsou A.A.E.Mo´se .
Classes: 50 packages by
Country: Benin Benin
Age: 32
All time rank: 7051 in Benin Benin
Week rank: 171 Up1 in Benin Benin Equal
Innovation award
Innovation award
Nominee: 23x

Winner: 2x

PHP Persistent Globals Maker.

As its name indicates, its purpose is to allow any one to build super globals
of their chosen names and then be able to access them any where.This package allows to build session type globals
which allows one file per user but also globals which are only relatives to the site itself which use only one file.

Except the basic access type like $object[]=2; and $object[1]=0 or unset($object[1])
you can use:

$tada['["papa"][0][6]']='tada';  //=> mean $tada["papa"][0][6]='tada';
unset($tada['["papa"][0][6]']); //=>mean unset($tada["papa"][0][6]);

if you wish to use  in you offset element like [,# or % you must use the delimiter %[ and ]% so
anything between these tags will be treat as simple string.

Many could find the shortcut above tricky and complex so they can use any array,define the input and  then use the
MergeWithExisting method to fill the global.See the example file for more details.

To create and/or use a super global the method suggested is :


or with the shortcut 


at the top of all your script where you want to use it.



will make available the super global $mysuperglobal every where you put the snippet above.
Note that this will automatically erase any global named the same as your super global so be 
sure to avoid conflict by choosing more or less unique name. 
Note that your name must respect the PHP requirements for variables names.

To create super global which act exactly like PHP sessions super global 
you must add the string likesession at the end of your chosen name


pgm_check_and_start('mysuperglobalLikesession');// the likesession part is insensitive

will make available the super global $mysuperglobal every where you put the snippet above.
this super global will act exactly as $_SESSION as it use one file per user and use the same
id as the PHP session id.

keep in mind that you can create as much super globals as wished provided that the names are different.

Also keep in mind that the package is optimized and made in order to never enter in conflict 
with native PHP globals.So never choose a name in this list or your global will never be created:

Also keep in mind that you don't need to manually save the state with the method saveState except  if you want.

a last but not least thing to keep in mind is how to make your super global available in functions,and classes;

function nowToglobal(){
	global $mysuperglobal;//then you can use it as you want


function nowToglobal(){


The state will be saved and you will be able to use it on another page on in the same page with  :

echo $mysuperglobal['now']; 

the existing methods and functions are:
array (
  'ContentSerialize' => 'return a serialized version of the global's contents not the global itself',
  'Create' => 'create the a new global and save it in the memory for further manipulation',
  'Destroy' => 'Delete globally the global and remove it completely from the memory',
  'MergeWithExisting' =>'Merge a given array with the global content',
  'SetInnerVal' => 'set an inner value',
  'UnsetInnerVal' => 'unset an inner value',
  '__clone' => 'throw an exception for a global can't be cloned',
  '__construct' => 'the purpose of construct but is useless here',
  '__debugInfo' => 'the purpose of __debugInfo',
  '__destruct' => 'save the current state if needed before the global local destruction',
  '__set_state' => 'Import a global in the current scope from a previously exported global ',
  '__sleep' => 'save the state of the current global before serialization',
  '__toString' => 'return a Json object of the global content',
  '__wakeup' => 'restore the global after unserialization',
  'abort' => 'abort any change brought to the current global',
  'clear' => 'clear the content of the global and also the log file',
  'clearLog' => 'Keep the global's content but clear the log file',
  'count' => 'the purpose of countable::count',
  'current' => 'the purpose of Iterator::current',
  'destroyOld' =>'start garbage collector to delete all old globals sessions',
  'detectleveltype' => 'private method to detect the variable type of a value in the global',
  'getsquarebracket' => 'retrieve all occurrences of bracketed values in a string',
  'globalExists' => 'check if a global already exists in memory',
  'jsonSerialize' => 'the purpose of JsonSerialiazable::JsonSerialize',
  'key' => 'the purpose of Iterator::key',
  'next' => 'the purpose of Iterator::next',
  'offsetExists' => 'the purpose of ArrayAccess::offsetExists',
  'offsetGet' => 'the purpose of ArrayAccess::offsetGet',
  'offsetSet' => 'the purpose of ArrayAccess::offsetSet',
  'offsetUnset' => 'the purpose of ArrayAccess::offsetUnset',
  'prev' => 'the purpose of prev',
  'rewind' => 'the purpose of Iterator::rewind',
  'saveState' => 'save the current state of the global',
  'synchronous_regenerate_session_id' => 'regenerate the session id but keep the global content under the new session id',
  'useExisting' => 'make the global content available if exists',
  'valid' =>'the purpose of Iterator::valid',

shortcut functions 
array (
  'pgm_check_and_start' => "check if the requested global exists any where in memory and make its contents available or create it if not exists ",
  'pgm_create' => 'create the global and store it in memory for further manipulation',
  'pgm_exists' => 'check if any global exists under the given name',
  'pgm_gc' => 'start the garbage collector',
  'pgm_regenerate_id' => 'regenerate the session id but keep the global content under the new session id',
  'pgm_start' => 'make the global content available',

for contributions ,feedback and other use the forum.
There is an example file in the package but if you really want to see the package in action download the lastest version
of my package lazy global classes and functions loader .
  Files folder image Files  
File Role Description
Plain text file PersistentGlobalsMaker.php Class class source
Accessible without login Plain text file readme.txt Doc. readme
Accessible without login Plain text file test.php Example example script

 Version Control Reuses Unique User Downloads Download Rankings  
This week:0
All time:9,199
This week:192Up
For more information send a message to info at phpclasses dot org.