Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Undefined object properties

    For some reason its saying that both the datetime_sent and sender_avatar properties are undefined. I don't see why this error is saying it when it is clearly with the print_r below.

    Code:
    A PHP Error was encountered
    
    Severity: Notice
    Message: Undefined property: stdClass::$datetime_sent
    Filename: models/messages_model.php
    Line Number: 72
    
    A PHP Error was encountered
    
    Severity: Notice
    Message: Undefined property: stdClass::$sender_avatar
    Filename: models/messages_model.php
    Line Number: 74
    There's a var_dump of an array at the bottom of my code. This is also included next.

    PHP Code:
    array(4) {
      [
    0]=>
      
    object(stdClass)#29 (8) {
        
    ["message_id"]=>
        
    string(1"1"
        
    ["subject"]=>
        
    string(12"Test Message"
        
    ["datetime_sent"]=>
        
    string(6"1 week"
        
    ["attachments"]=>
        
    NULL
        
    ["message_content"]=>
        
    string(446"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
        
    ["sender_name"]=>
        
    string(16"Jeffrey Davidson"
        
    ["sender_email_address"]=>
        
    string(20"xtremer360@yahoo.com"
        
    ["sender_avatar"]=>
        
    string(82"http://dev.kansasout...rs/avatar5.jpg"
      
    }
      [
    1]=>
      
    object(stdClass)#30 (8) {
        
    ["message_id"]=>
        
    string(1"2"
        
    ["subject"]=>
        
    string(18"Testing PM Message"
        
    ["datetime_sent"]=>
        
    string(19"2012-09-22 18:27:25"
        
    ["attachments"]=>
        
    string(37"["file1.jpg","file2.jpg","file3.jpg"]"
        
    ["message_content"]=>
        
    string(51"This is jsut a test of the personal message system!"
        
    ["sender_name"]=>
        
    string(11"Frank Scott"
        
    ["sender_email_address"]=>
        
    string(24"frankscott@testemail.com"
        
    ["sender_avatar"]=>
        
    NULL
      
    }
      [
    2]=>
      
    object(stdClass)#31 (8) {
        
    ["message_id"]=>
        
    string(1"3"
        
    ["subject"]=>
        
    string(16"Testing Whatever"
        
    ["datetime_sent"]=>
        
    string(19"2012-10-04 05:03:09"
        
    ["attachments"]=>
        
    NULL
        
    ["message_content"]=>
        
    string(11"dak;fdaf;ld"
        
    ["sender_name"]=>
        
    string(11"Frank Scott"
        
    ["sender_email_address"]=>
        
    string(24"frankscott@testemail.com"
        
    ["sender_avatar"]=>
        
    NULL
      
    }
      [
    3]=>
      
    object(stdClass)#32 (3) {
        
    ["attachments"]=>
        array(
    3) {
          [
    0]=>
          array(
    2) {
            [
    "file_name"]=>
            
    string(9"file1.jpg"
            
    ["is_file"]=>
            
    bool(false)
          }
          [
    1]=>
          array(
    2) {
            [
    "file_name"]=>
            
    string(9"file2.jpg"
            
    ["is_file"]=>
            
    bool(false)
          }
          [
    2]=>
          array(
    2) {
            [
    "file_name"]=>
            
    string(9"file3.jpg"
            
    ["is_file"]=>
            
    bool(false)
          }
        }
        [
    "datetime_sent"]=>
        
    string(8"42 years"
        
    ["sender_avatar"]=>
        
    string(81"http://dev.kansasout...ars/avatar.jpg"
      
    }

    PHP Code:
    /**
             * Gets all or last $x number of personal messages of the specified user
             *
             * @param integer $user_id User ID of the user specified
             * @param integer $limit Limit of how many messages to retrieve
             * @return object/NULL
             */
            
    public function get_personal_messages($user_id$limit NULL$timezone)
            {
                    
    $this->db->select('personal_messages.message_id');
                    
    $this->db->select('personal_messages.subject');
                    
    $this->db->select('personal_messages.datetime_sent');
                    
    $this->db->select('personal_messages.attachments');
                    
    $this->db->select('personal_messages.message_content');
                    
    $this->db->select('CONCAT(users.first_name, " ", users.last_name) AS sender_name'FALSE);
                    
    $this->db->select('users.email_address AS sender_email_address');
                    
    $this->db->select('user_profiles.user_avatar AS sender_avatar');
                    
    $this->db->from('personal_messages');
                    
    $this->db->join('users''users.user_id = personal_messages.from_user_id');
                    
    $this->db->join('user_profiles''users.user_id = user_profiles.user_id');
                    
    $this->db->where('personal_messages.to_user_id'$user_id);
                    if (
    $limit != NULL)
                    {
                            if (
    is_numeric($limit))
                            {
                                    
    $this->db->limit($limit);
                            }
                    }
                    
    $query $this->db->get();
                    
    $personal_messages $query->result();
                    if (
    count($personal_messages) > 0)
                    {
                            for (
    $x 0$x count($personal_messages); $x++)
                            {
                                    
    $attachments $personal_messages[$x]->attachments;
                                    if (
    $this->functions_model->null_check($attachments) === FALSE)
                                    {
                                            
    $attachments json_decode($attachmentsTRUE);
                                            for (
    $x 0$x count($attachments); $x++)
                                            {
                                                    
    $file_name $attachments[$x];
                                                    if (
    $this->functions_model->is_file('assets/downloads/'.$file_nameFALSE) === TRUE)
                                                    {
                                                            
    $attachments[$x] = array('file_name' => $file_name'is_file' => TRUE);                                          
                                                    }
                                                    else
                                                    {
                                                     
    $attachments[$x] = array('file_name' => $file_name'is_file' => FALSE);       
                                             }
                                     }
                                     
    $personal_messages[$x]->attachments $attachments;
                             }
                                    
    $personal_messages[$x]->datetime_sent $this->functions_model->actual_time('d F Y g:i a'$timezonestrtotime($personal_messages[$x]->datetime_sent));
                                    
    $avatar $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/avatar.jpg';
                                    if (
    $this->functions_model->null_check($personal_messages[$x]->sender_avatar) === FALSE)
                                    {
                                            if (
    $this->functions_model->is_file('assets/themes/supr/images/avatars/'.$personal_messages[$x]->sender_avatarFALSE) === TRUE)
                                            {
                                                    
    $avatar $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/'.$personal_messages[$x]->sender_avatar;
                                            }
                                    }
                                    
    $personal_messages[$x]->datetime_sent $this->functions_model->time_since(strtotime($personal_messages[$x]->datetime_sent));
                                    
    $personal_messages[$x]->sender_avatar $avatar;
                            }
                    }
                    echo 
    '<pre>';
                    
    var_dump($personal_messages);
                    echo 
    '</pre>';
                    die();
                    return 
    $personal_messages;
            } 
    Last edited by CoolAsCarlito; 10-11-2012 at 07:20 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Something is wrong with this chunk of code because it is throwing attachments in its own first level array. So I need to figure out how I can work with the attatchments correctly to where it will apply the tasks below to each of the items in the first level array.

    PHP Code:
    $attachments $personal_messages[$x]->attachments;
                    if (
    $this->functions_model->null_check($attachments) === FALSE)
                    {
                        
    $attachments json_decode($attachmentsTRUE);
                        for (
    $x 0$x count($attachments); $x++)
                        {
                            
    $file_name $attachments[$x];
                            if (
    $this->functions_model->is_file('assets/downloads/'.$file_nameFALSE) === TRUE)
                            {
                                
    $attachments[$x] = array('file_name' => $file_name'is_file' => TRUE);                        
                            }
                            else
                            {
                                
    $attachments[$x] = array('file_name' => $file_name'is_file' => FALSE);    
                            }
                        }
                        
    $personal_messages[$x]->attachments $attachments;
                    } 

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Ignore that for now.
    What is the result of the structure on creation:
    PHP Code:
    $personal_messages $query->result();
    print 
    var_dump($personal_messages); 

  • Users who have thanked Fou-Lu for this post:

    CoolAsCarlito (10-11-2012)

  • #4
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Thank you for the quick reply.

    PHP Code:
    array(3) {
      [
    0]=>
      
    object(stdClass)#29 (8) {
        
    ["message_id"]=>
        
    string(1"1"
        
    ["subject"]=>
        
    string(12"Test Message"
        
    ["datetime_sent"]=>
        
    string(19"2012-10-02 18:27:25"
        
    ["attachments"]=>
        
    NULL
        
    ["message_content"]=>
        
    string(446"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
        
    ["sender_name"]=>
        
    string(16"Jeffrey Davidson"
        
    ["sender_email_address"]=>
        
    string(20"xtremer360@yahoo.com"
        
    ["sender_avatar"]=>
        
    string(11"avatar5.jpg"
      
    }
      [
    1]=>
      
    object(stdClass)#30 (8) {
        
    ["message_id"]=>
        
    string(1"2"
        
    ["subject"]=>
        
    string(18"Testing PM Message"
        
    ["datetime_sent"]=>
        
    string(19"2012-09-22 18:27:25"
        
    ["attachments"]=>
        
    string(37"["file1.jpg","file2.jpg","file3.jpg"]"
        
    ["message_content"]=>
        
    string(51"This is jsut a test of the personal message system!"
        
    ["sender_name"]=>
        
    string(11"Frank Scott"
        
    ["sender_email_address"]=>
        
    string(24"frankscott@testemail.com"
        
    ["sender_avatar"]=>
        
    NULL
      
    }
      [
    2]=>
      
    object(stdClass)#31 (8) {
        
    ["message_id"]=>
        
    string(1"3"
        
    ["subject"]=>
        
    string(16"Testing Whatever"
        
    ["datetime_sent"]=>
        
    string(19"2012-10-04 05:03:09"
        
    ["attachments"]=>
        
    NULL
        
    ["message_content"]=>
        
    string(11"dak;fdaf;ld"
        
    ["sender_name"]=>
        
    string(11"Frank Scott"
        
    ["sender_email_address"]=>
        
    string(24"frankscott@testemail.com"
        
    ["sender_avatar"]=>
        
    NULL
      
    }


  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    First line of the for loop, add:
    PHP Code:
    printf("Evaluating record: %d" PHP_EOL$x); 
    Can you post the errors with that in it? We need to find out which one(s) this is coming off of.

  • Users who have thanked Fou-Lu for this post:

    CoolAsCarlito (10-11-2012)

  • #6
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Response is this...

    Evaluating record: 0 Evaluating record: 1 Evaluating record: 2

    And there aren't any errors present. It was just the formation of adding in the logic with the attachments to the multidimensional array.

  • #7
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Any more thoughts on the topic?

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Wait, you're original post has errors in it though. That's what I was looking for, to determine which one(s) of the records in the iteration threw those errors.
    I mean to me it looks like the error is here:
    Code:
    $personal_messages[$x]->datetime_sent = $this->functions_model->actual_time('d F Y g:i a', $timezone, strtotime($personal_messages[$x]->datetime_sent));
    $avatar = $this->functions_model->site_url().'assets/themes/'.$this->config->item('default_theme').'/images/avatars/avatar.jpg';
    if ($this->functions_model->null_check($personal_messages[$x]->sender_avatar) === FALSE)
    With a stdclass object, you shouldn't be receiving an error whilst writing to a property, only while attempting to retrieve one that hasn't yet been set. Above ::$datetime_sent is used in the strtotime, and ::$sender_avatar is used in null_check.

    So what I was hoping to see was the record counter in conjunction with the above errors.
    Code:
    Evaluating Record: 1
    A PHP Error was encountered
    
    Severity: Notice
    Message: Undefined property: stdClass::$sender_avatar
    Filename: models/messages_model.php
    Line Number: 74
    And so forth.

    Are you still getting that original error?

  • #9
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Yes I am.

  • #10
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    The whole code block with the attachments is what's causing the errors because if I comment it out then the array works fine however I still need it to run the null check and also have it run the other tasks.

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by CoolAsCarlito View Post
    The whole code block with the attachments is what's causing the errors because if I comment it out then the array works fine however I still need it to run the null check and also have it run the other tasks.
    That makes no sense. The error itself isn't related to the use of the attachments, it indicates an issue with the datetime_sent and sender_avatar.
    Can you confirm which lines are 72 and 74?

  • #12
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Then why is it when I remove attachments code I no longer get those error messages

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I don't know, it doesn't make sense that is the error you would receive by a block that alters a different property. The only time you should hit an error is if you completely reassign the object itself, or if you read that property, and you don't do either until after that block of code.

  • #14
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    What's the problem then?

  • #15
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Any more ideas?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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