Skip to content

Instantly share code, notes, and snippets.

@RalfAlbert
Created January 8, 2012 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RalfAlbert/1578910 to your computer and use it in GitHub Desktop.
Save RalfAlbert/1578910 to your computer and use it in GitHub Desktop.
Simple DataContainer with overwrite protection
<?php
class DataContainer
{
private static $data = array();
public static function __set( $name, $value ){
if( ! isset( self::$data[$name] ) )
self::$data[$name] = $value;
else
return FALSE;
return TRUE;
}
public static function __get( $name ){
if( isset( self::$data[$name] ) )
return self::$data[$name];
else
return NULL;
}
}
$dc = new DataContainer;
$dc->FILE = basename( __FILE__ );
var_dump( $dc->FILE );
$dc_two = new DataContainer;
$dc_two->FILE = 'mettigel';
var_dump( $dc->FILE );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment