Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2012, 07:14 PM   PM User | #1
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
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..
CoolAsCarlito is offline   Reply With Quote
Old 10-11-2012, 08:12 PM   PM User | #2
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
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;
                } 
CoolAsCarlito is offline   Reply With Quote
Old 10-11-2012, 08:16 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Ignore that for now.
What is the result of the structure on creation:
PHP Code:
$personal_messages $query->result();
print 
var_dump($personal_messages); 
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
CoolAsCarlito (10-11-2012)
Old 10-11-2012, 08:23 PM   PM User | #4
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
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
  
}

CoolAsCarlito is offline   Reply With Quote
Old 10-11-2012, 08:31 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
CoolAsCarlito (10-11-2012)
Old 10-11-2012, 08:35 PM   PM User | #6
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
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.
CoolAsCarlito is offline   Reply With Quote
Old 10-11-2012, 09:36 PM   PM User | #7
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
Any more thoughts on the topic?
CoolAsCarlito is offline   Reply With Quote
Old 10-11-2012, 09:48 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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?
Fou-Lu is offline   Reply With Quote
Old 10-11-2012, 10:10 PM   PM User | #9
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
Yes I am.
CoolAsCarlito is offline   Reply With Quote
Old 10-11-2012, 10:24 PM   PM User | #10
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
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.
CoolAsCarlito is offline   Reply With Quote
Old 10-11-2012, 11:33 PM   PM User | #11
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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?
Fou-Lu is offline   Reply With Quote
Old 10-11-2012, 11:46 PM   PM User | #12
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
Then why is it when I remove attachments code I no longer get those error messages
CoolAsCarlito is offline   Reply With Quote
Old 10-12-2012, 02:08 AM   PM User | #13
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 10-12-2012, 02:32 AM   PM User | #14
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
What's the problem then?
CoolAsCarlito is offline   Reply With Quote
Old 10-12-2012, 05:30 PM   PM User | #15
CoolAsCarlito
Regular Coder

 
Join Date: Jun 2008
Posts: 679
Thanks: 114
Thanked 2 Times in 2 Posts
CoolAsCarlito can only hope to improve
Any more ideas?
CoolAsCarlito is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:39 AM.


Advertisement
Log in to turn off these ads.