🙂
I have a small oo structure.:rolleyes:
I create a manager class to handle lower application level objects. However this manager is created when necessary, so the manager objects are created when called from a function. I think the manager object has a scope problem.
In the version below, since the manager is created by a function called at the global level, the nrAsset returns 3 as I expect.
<?
require("myClasses.php4");
$myCurrencySystem = new currencySystem();
$myCurrencyManager = $myCurrencySystem->getManager($ctype);
$ctype = "dollar";
processCurrencyEntry(0, $ctype, 12, 15);
processCurrencyEntry(1, $ctype, 13, 16);
processCurrencyEntry(2, $ctype, 14, 17);
print (nrAsset($ctype)." entries<br>\n");
?>
<? function processCurrencyEntry($tstamp, $ctype, $value, $quantity){
global $myCurrencyManager,$myCurrencySystem ;
//$myCurrencyManager = $myCurrencySystem ->getManager($ctype);
$new = new currencyAsset($tstamp, $value, $quantity);
array_push($myCurrencyManager->assetList2, $new);
}?>
<? function nrAsset($type){
global $myCurrencyManager,$myCurrencySystem ;
return count($myCurrencyManager->assetList2);
}?>
However, this version returns only 1, because the function that creates the manager is called from a function. This 1, I cant understand.
<?
require("ertugrulClasses.php4");
$myCurrencySystem = new currencySystem();
//$myCurrencyManager = $myCurrencySystem->getManager($ctype);
$ctype = "dollar";
processCurrencyEntry(0, $ctype, 12, 15);
processCurrencyEntry(1, $ctype, 13, 16);
processCurrencyEntry(2, $ctype, 14, 17);
print (nrAsset($ctype)." entries<br>\n");
?>
<? function processCurrencyEntry($tstamp, $ctype, $value, $quantity){
global $myCurrencyManager,$myCurrencySystem ;
$myCurrencyManager = $myCurrencySystem ->getManager($ctype);
$new = new currencyAsset($tstamp, $value, $quantity);
array_push($myCurrencyManager->assetList2, $new);
}?>
<? function nrAsset($type){
global $myCurrencyManager,$myCurrencySystem ;
return count($myCurrencyManager->assetList2);
}?>
I dont understand this problem.
I dont understand this behavior.
Sincerely,
Koray Berk