I want to access Static method properties to other static method. I am trying to access it via:
public static function getGender($user) {
$user_data[] = Common::getSomeUsers(true);
$ssn_to_gender[] = array();
foreach($user_data as $u_data){
foreach($u_data as $key => $user){
'$key:' .$user['ssn'];
$ssn = $user['ssn'] . "<br/>";
//echo $ssn;
$ssn_gender= substr($ssn,7,-6) . "<br/>" ;
$dob_gender= substr($ssn,0,6) . "<br/>" ;
echo $dob_gender;
if($ssn_gender % 2 == 0 )
{
echo 'F' . '</br>';
$ssn_to_gender[$user['ssn']] = 'F';
}
elseif($ssn_gender % 2 == 1)
{
echo 'M' .'<br/>';
$ssn_to_gender[$user['ssn']] = 'M';
}
}
}
return $ssn_to_gender;
return $dob_gender;
//$user= array();
//echo Common::getSomeUsers($user);
}
public static function getAge( $user ) {
self::getGender(true);
Common::$dob_gender;
}
Common::getAge($userid='');
echo Common::$dob_gender;
I am trying to access $dob_gender
variable in get_Age()
method from getGender()
method.
But unable to get the $dob_gender
. Please guide I am new with PHP and object oriented programming.
Thanks.
I would think about doing a standard method instead of a series of static methods:
class Common
{
private $ssn_to_gender,
$dob_gender;
/**
* @returns Itself (Common object)
*/
public function getGender($user)
{
$user_data[] = $this->getSomeUsers(true);
$this->ssn_to_gender[] = array();
foreach($user_data as $u_data){
foreach($u_data as $key => $user){
$ssn = $user['ssn'];
$ssn_gender = substr($ssn,7,-6);
$this->dob_gender = substr($ssn,0,6);
if($ssn_gender % 2 == 0 ) {
$this->ssn_to_gender[$user['ssn']] = 'F';
}
elseif($ssn_gender % 2 == 1) {
$this->ssn_to_gender[$user['ssn']] = 'M';
}
}
}
return $this;
}
/**
* @returns The corresponding private variable
*/
public function getSSNToGender()
{
return $this->ssn_to_gender;
}
/**
* @returns The corresponding private variable
*/
public function getDOBGender()
{
return $this->dob_gender;
}
/**
* @question I am not sure the purpose of this method. Presumably you need to
* do more in the way of script otherwise you would just do the
* getGender() method instead
*/
public function getAge($userid)
{
# I am returning this but presumably you want to do something else??
return $this->getGender($userid);
}
}
To use would be like:
$Common = new Common();
$Age = $Common->getAge($userid);
print_r($Age->getDOBGender());
print_r($Age->getSSNToGender());