static function Object2Array (&$destination_array,$mapper=null, $source_class) {
if (!$mapper) $mapper = 'pleaseMap';
if (is_string($mapper) ) {
// if the source specification map is not explicitly passed
// to us, look for a 'pleaseMap' array in the source class
//
// if the source specification map IS explicitly passed
// as a string, we take it as an alternat map name in the source class
//
// The source class will usually be the caller's class
$mapper = &$source_class->$mapper;
} // otherwise mapper is an array map passed to us

// loop through the mapper array grabbing the proper source class variables
// placing them in the destination
// either by setting the value directly or calling the correct 'set' method
foreach ($mapper as $dest=>$srcloc ) {
// is there a getvalue method in the source?
if (method_exists($source_class,$srcloc)) {
$val = $source_class->$srcloc();
} else $val = $source_class->$srcloc;

$destination_array[$dest]= $val;
}
return @$destination_array;
}

static function Object2Object (&$destination_class,$mapper=null, $source_class) {
if (!$mapper) $mapper = 'pleaseMap';
if (is_string($mapper) ) {
// if the source specification map is not explicitly passed
// to us, look for a 'pleaseMap' array in the destination class
//
// if the source specification map IS explicitly passed
// as a string, we take it as an alternat map name in the destination class
//
// The destination class will usually be the caller's class
$mapper = &$destination_class->$mapper;
} // otherwise mapper is an array map passed to us

// loop through the mapper array grabbing the proper source class variables
// placing them in the destination
// either by setting the value directly or calling the correct 'set' method
foreach ($mapper as $destloc=>$srcvar ) {
// is there a getvalue method in the source to get the srcvar?
if (method_exists($source_class,$srcvar)) {
$val = $source_class->$srcvar( $destloc);
} else $val = $source_class->$srcvar;

static function Array2Object (&$destination_class,$mapper=null, $source_array='_POST') {
if (!$mapper) $mapper = 'pleaseMap';
if (!$source_array) $source_array = '_POST';
if (is_string($source_array) ) {
// if the source_array is unspecified or a string, we assume it is
// a global array,like _POST or _GET or such, otherwise it is an array that
// the caller has passed to us explicitly
global ${$source_array};
$source_array = &${$source_array};
}
if (is_string($mapper) ) {
// if the source specification map is not explicitly passed
// to us, look for a 'pleaseMap' array in the destination class
//
// if the source specification map IS explicitly passed
// as a string, we take it as an alternat map name in the destination class
//
// The destination class will usually be the caller's class
$mapper = &$destination_class->$mapper;
// and place them in the destination
} //otherwise the mapper is an array passed by the caller

// if the source specification map is passed explicitly as an array, we
// loop through the map grabbing the proper source array variables
// placing them in the destination
// either by setting the value directly or calling the correct 'set' method
foreach ($mapper as $dest=>$var ) {
if (method_exists($destination_class,$dest)) {
$destination_class->$dest( $source_array[$var],$var);
} else $destination_class->$dest = $source_array[$var];
}
return @$destination_class;
}

echo("\n\nArray to Object test:");
echo("\nNow mapping source using 'otherMap' specification arrray from an array rather than a class\n");
echo("\n expected results 'just a constant' in myvalue, 'just a constant' in var4, and 1000 in var5\n");
pleaseMap::Array2Object($c1,'otherMap',array('grabValue'=> 'just a constant', 'var1' =>1000));
$c1->debug();