interface iQVar extends BaseIface {
// SETUP
static function AsNew() : self;
static function FromVarRef(&$v) : self;
static function FromAValue(array $ar, int|string $vKey, ArrayOptsEnum $eOpt=ArrayOptsEnum::Nothing) : self;
static function FromOAValue(ArrayIface $oa, int|string $vKey, ArrayOptsEnum $eOpt=ArrayOptsEnum::Nothing) : self;
// ACCESS: typeless
function HasIt() : bool;
function ZapIt();
function TypeOk(mixed $v) : bool;
function WithOAValue(ArrayIface $oa, int|string $key, ArrayOptsEnum $eOpt=ArrayOptsEnum::Nothing) : void;
// ++ ACCESS: basic types ++ //
//// - int
function HasInt() : bool;
function SetInt(int $n);
function SetIntNz(?int $n);
function &GetInt() : int;
function GetIntNz(int $nDefault=0) : int;
function RefInt(int &$n) : void;
//// - string
function HasStr() : bool;
function SetStr(string $s);
function SetStrNz(?string $s);
function &GetStr() : string;
function GetStrNz(string $sDefault='', string $sPfx='', string $sSfx='') : string;
function RefStr(string &$s) : void;
//// - object
function HasObj() : bool;
function SetObj(object $o);
function SetObjNz(?object $o);
function GetObj() : object;
function GetObjNz(object $oDefault=NULL) : ?object;
/*
// ACCESS: undeclarable
// These can't be declared because their types change in each podling. "mixed" is replaced by the corresponding type.
function SetIt(mixed $n);
function SetItNz(?mixed $v);
function &GetIt() : mixed;
function GetItNz(mixed $vDefault=0) : mixed;
function RefIt(mixed &$v) : void;
function SetDefault(mixed $n);
*/
}
/**
* NOTE:
* 2024-07-19 There is an implied SetIt(variant) method, but we can't declare it here
* because that would prevent $v from having a required type.
*/
trait tQVar {
// ++ SETUP ++ //
public static function AsNew() : iQVar { return new static; }
public static function FromVarRef(&$v) : iQVar {
$oThis = new static;
$oThis->RefIt($v);
return $oThis;
}
public static function FromValue(mixed $v) : iQVar {
$oThis = new static;
$oThis->SetIt($v);
return $oThis;
}
public static function FromAIndex(array $ar, int|string $vKey, ArrayOptsEnum $eOpt=ArrayOptsEnum::Nothing) : iQVar {
$oThis = new static;
$oThis->WithAIndex($ar,$key,$eOpt);
return $oThis;
}
public static function FromAValue(array $ar, int|string $vKey, ArrayOptsEnum $eOpt=ArrayOptsEnum::Nothing) : iQVar {
$oThis = new static;
$oThis->WithAValue($ar,$key,$eOpt);
return $oThis;
}
public static function FromOAValue(ArrayIface $oa, int|string $key, ArrayOptsEnum $eOpt=ArrayOptsEnum::Nothing) : iQVar {
$oThis = new static;
$oThis->WithOAValue($oa,$key,$eOpt);
return $oThis;
}
// -- SETUP -- //
// ++ ACCESS: typeless ++ //
protected $v = NULL;
public function ZapIt() { $this->v = NULL; }
protected function WithAIndex(array $ar, int|string $snKey, ArrayOptsEnum $eOpt=ArrayOptsEnum::Nothing) : void {
$isFnd = FALSE;
if (array_key_exists($snKey,$ar)) {
$this->SetIt($snKey);
}
}
public function WithAValue(array $ar, int|string $snKey, ArrayOptsEnum $eOpt=ArrayOptsEnum::Nothing) : void {
$isFnd = FALSE;
if (array_key_exists($snKey,$ar)) {
$vDup =& $ar[$snKey];
$isFnd = $this->TypeOk($vDup);
}
if (!$isFnd) {
$isFnd = $this->HandleAbsent($snKey,$eOpt);
}
if ($isFnd) {
$this->RefIt($vDup);
}
}
public function WithOAValue(ArrayIface $oa, int