View Single Post
Old 12-17-2008, 09:08 PM   #5 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Like the latter posts have stated, $member isnt defined anywhere in the scope of the called method, hence the notice about an undefined variable 'member'.
Also remove the single quotes from around $variable otherwise PHP will interpret that statement to be thus:

'Access the array element $variable within the $member
array' and not 'Access the array element msn within the $member array' etc as you were intending.

This is because in PHP a variable name witin single quotes will not be expanded out and as a result will be treated as a normal string.
However if you were to use double quotes PHP would
interpolate variable values in place of the variable names but in this case neither is needed, the variable name will do fine:
PHP Code:
$member[$variable]; 
Heres just a breif idea of what i think you are trying to achieve:
PHP Code:
class member
{
    private 
$member = array('msn' => 'msn@contact.com''other' => 'test@test.com');
    public function 
user($variable)
    {
        return 
$variable;
    }
    public function 
contact($variable)
    {
        return 
$this->member[$variable];
    }
}
$member = new member();

echo 
$member->contact('msn'); 
Obviously you will need to change the hard coded array property to be something dynamic (i.e. from the DB) but this should show you enough information to get you started.

Hope that helps.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote