SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    145
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Using External variable in a function of a class

    I'm trying to pass a variable in another class calling it on top of the class.. something like this..

    PHP Code:
    include_once('classes/profile.class.php');
    $email=$profile->getField('email'); //<-- the email address prints here if ecoed but doesn't work inside the class .. example below..
    class someClass
    {

    public function 
    show_answer($id$ticketInfo)
            {
                if(
    $ticketInfo->res == "true")
                {
                    
    $this->_ticketInfo = new ticketInfo();
                    echo 
    '<article style="margin-top:-18px;">
                                <section class="well well-small mePadd">
                                    <h2 class="meFont" style="padding-bottom:30px;"><span class="icon-comment meMarg"></span> Answer</h2>'
    ;
                    for (
    $i 0$i count($ticketInfo->id); $i++)
                    {
                        if(
    $ticketInfo->id[$i] == $id)
                        {
                            
    $message urldecode($ticketInfo->msg[$i]);
                            
    $message str_replace("\'""'"$message);
                            
    $user_name $this->_ticketInfo->getuser($ticketInfo->userId[$i]);
                            
    $user_name json_decode($user_name);
                            if(empty(
    $user_name))
                            {
                                
    $full_name "this user deleted";
                            }
                            else
                            {
                                
    $full_name $user_name->name.' '.$user_name->lastname;
                            }
                            
    $dateModified self::change_date_format($ticketInfo->dateAded[$i]);
                            
    $dateActivity self::change_date_format($ticketInfo->dateActivity[$i]);
                            
    $adminInfo self::getAdminInfo($email); //<-- this variable $email is not being able to pull the email address
    ... rest of the code


    }


    Any idea why $email is not being pulled up there?

    Thanks

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,276
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    You'll need to use the global keyword in order to use a global variable.

    That being said, don't use global variables. Your code will harder to understand and predict, harder to reuse and test, and errors will be easier to make and harder to trace.
    "First make it work. Then make it better."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •