[PHP] Variable Scope from child to parent
- Date: Wed, 14 May 2008 15:33:36 -0700
- From: Tyson Vanover <tvanover@xxxxxxx>
- Subject: [PHP] Variable Scope from child to parent
I am trying to get a child class to pass an array of valid keys to it's parent when the constructor is run, and the parent appends the data to one of it's array of valid keys. Then it walks through an array pulling out values that have valid keys, and putting them in an array for processing later. I have tried explicitly stating the variable scope.
abstract class parentclass
{
protected $vkeys= array('title1','title2','title3');
protected $a;
function __construct($set = NULL, $special = NULL)
{
self::$this->vkeys= array_merge(self::$this->vkeys, $special);
foreach($set as $key=>$value)
{
if (in_array($key,self::$this->vkeys))
{
$this->a[$key] = $value;
}
}
print_r(self::$this->vkeys); //output below
print_r(self::$this->a); //output below
}
}
class childclass extends parentclass
{
protected $vkeys= array('titleA', 'titleB', 'TitleC');
function __construct($set, $special = NULL)
{
parent::__construct($set, self::$this->vkeys);
unset(self::$this->vkeys);
}
}
Unfortunately it seems to duplicate the child's array instead of
appending. Explicitly stating scope does not seem to help.
print_r(self::$this->vkeys); Array ( [0] => titleA [1] => titleB [2] => titleB [3] => titleA [4] => titleB [5] => titleB ) print_r(self::$this->a); Array() Any thoughts? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
- Follow-Ups:
- Re: [PHP] Variable Scope from child to parent
- From: Gabriel Sosa
- Re: [PHP] Variable Scope from child to parent
- Prev by Date: Re: [PHP] Tracking down the elusive "expecting T_PAAMAYIM_NEKUDOTAYIM"
- Next by Date: Re: [PHP] Mic check 1, 2, 3...
- Previous by thread: [PHP] Mic check 1, 2, 3...
- Next by thread: Re: [PHP] Variable Scope from child to parent
- Index(es):