note 120184 deleted from security.globals by cmb

From: Date: Sun, 17 Jan 2021 13:57:03 +0000
Subject: note 120184 deleted from security.globals by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216181@lists.php.net to get a copy of this message
Note Submitter: tomas at hauso dot sk ---- for PHP5.4+ you can use registry pattern instead global final class MyGlobal { private static $data = array(); public static function get($key) { return (isset(static::$data[$key]) ? static::$data[$key] : null); } public static function set($key, $value) { static::$data[$key] = $value; } public static function has($key) { return isset(static::$data[$key]); } } // END OF CLASS $var1 = 'I wanna be global'; MyGlobal::set('bar', $var1 ); // set var to registry function foo(){ echo MyGlobal::get('bar'); // get var from registry } foo();

« previous php.notes (#216181) next »