Problem with $this

Reply

Join Date: Nov 2007
Posts: 13
Reputation: Hugo Brand is an unknown quantity at this point 
Solved Threads: 0
Hugo Brand Hugo Brand is offline Offline
Newbie Poster

Problem with $this

 
0
  #1
Aug 22nd, 2009
Hi

I've been doing a study of some PHP code developed by another author in 2002.

The article could be found at:
http://www.devshed.com/c/a/PHP/Build...ient-part-2/3/

The functions I need help with in understanding are:
function parse($structure) //custom function developed by author
function get_attachments($arr) //custom function developed by author

The following line gave me difficulties:
  1. $this = $parts[$x];

I have studied this line of code and would like to know if $this has some sort of special meaning in PHP?

I tried to change $this to $result and the application seemed to be working, but not giving the correct result.

Any help would be appreciated.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 53
Reputation: SimonMayer is an unknown quantity at this point 
Solved Threads: 10
SimonMayer SimonMayer is offline Offline
Junior Poster in Training

Re: Problem with $this

 
0
  #2
Aug 22nd, 2009
Originally Posted by Hugo Brand View Post
I have studied this line of code and would like to know if $this has some sort of special meaning in PHP?
Yes, $this is used within classes. Is this code object oriented, i.e. has the author included any classes? If not, $this should not be used.

If it is object oriented code, $this may be used deliberately and changing it to something else might make one bit of your code work fine and break it elsewhere.

I would suggest taking a look at this: http://us3.php.net/manual/en/language.oop5.basic.php
Regards,

Simon Mayer
Website design by Ribbontree
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 53
Reputation: SimonMayer is an unknown quantity at this point 
Solved Threads: 10
SimonMayer SimonMayer is offline Offline
Junior Poster in Training

Re: Problem with $this

 
0
  #3
Aug 22nd, 2009
To clarify, does the line
  1. $this = $parts[$x];
appear within something like the following
  1. class NameOfTheObject
  2. {
  3. }
Regards,

Simon Mayer
Website design by Ribbontree
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 13
Reputation: Hugo Brand is an unknown quantity at this point 
Solved Threads: 0
Hugo Brand Hugo Brand is offline Offline
Newbie Poster

Re: Problem with $this

 
0
  #4
Aug 22nd, 2009
Originally Posted by SimonMayer View Post
To clarify, does the line
  1. $this = $parts[$x];
appear within something like the following
  1. class NameOfTheObject
  2. {
  3. }
SimonMayer

No, from reading the line code it looks as if it appeared only in a function, not a class.

Thank you for providing a link, I will look at it when I have some time available.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 340
Reputation: Josh Connerty is an unknown quantity at this point 
Solved Threads: 26
Josh Connerty's Avatar
Josh Connerty Josh Connerty is offline Offline
Posting Whiz

Re: Problem with $this

 
0
  #5
Aug 22nd, 2009
Then no $this should not change the script, the issue you are probably having is that the varibale is being called later on in the script. You may need to "Find" $this using your text editor and change it to $result.

Please post your current document in [code=php] tags.
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.

My Liveperson: http://liveperson.com/josh-connerty/
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 13
Reputation: Hugo Brand is an unknown quantity at this point 
Solved Threads: 0
Hugo Brand Hugo Brand is offline Offline
Newbie Poster

Re: Problem with $this

 
0
  #6
Aug 23rd, 2009
Josh Connerty

This reply contains the original code in respect to the author who developed it, that I was studying.

  1. <?
  2. // define some constants
  3. // message types
  4. $type = array("text", "multipart", "message", "application", "audio",
  5. "image", "video", "other");
  6. // message encodings
  7. $encoding = array("7bit", "8bit", "binary", "base64", "quoted-printable",
  8. "other");
  9.  
  10. // parse message body
  11. function parse($structure)
  12. {
  13. global $type;
  14. global $encoding;
  15.  
  16. // create an array to hold message sections
  17. $ret = array();
  18.  
  19. // split structure into parts
  20. $parts = $structure->parts;
  21.  
  22. for($x=0; $x<sizeof($parts); $x++)
  23. {
  24. $ret[$x]["pid"] = ($x+1);
  25.  
  26. $this = $parts[$x];
  27.  
  28. // default to text
  29. if ($this->type == "") { $this->type = 0; }
  30. $ret[$x]["type"] = $type[$this->type] . "/" . strtolower($this->subtype);
  31.  
  32. // default to 7bit
  33. if ($this->encoding == "") { $this->encoding = 0; }
  34. $ret[$x]["encoding"] = $encoding[$this->encoding];
  35.  
  36. $ret[$x]["size"] = strtolower($this->bytes);
  37.  
  38. $ret[$x]["disposition"] = strtolower($this->disposition);
  39.  
  40. if (strtolower($this->disposition) == "attachment")
  41. {
  42. $params = $this->dparameters;
  43. foreach ($params as $p)
  44. {
  45. if($p->attribute == "FILENAME")
  46. {
  47. $ret[$x]["name"] = $p->value;
  48. break;
  49. }
  50. }
  51. }
  52. }
  53.  
  54. return $ret;
}
?>

Changing all $this to $result, made the application work, but with unexpected results. I have debugged most of the conditional statements above and my major problem lied with this if statement:

if (strtolower($this->disposition) == "attachment")

It was suppose to read the conditional statement, but instead it doesn't find any value inside of the $this->disposition containing an "attachment" string value.

Any comments would still be appreciated.
Thanks
Last edited by Hugo Brand; Aug 23rd, 2009 at 2:30 am.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: Problem with $this

 
0
  #7
Aug 23rd, 2009
It looks like you have Object Oriented code there, if the file in question called by another file (include, require....)?
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 340
Reputation: Josh Connerty is an unknown quantity at this point 
Solved Threads: 26
Josh Connerty's Avatar
Josh Connerty Josh Connerty is offline Offline
Posting Whiz

Re: Problem with $this

 
1
  #8
Aug 23rd, 2009
Yes Xan is right, there is deffinetly object oriented coding in their. $this does seem to be a class of some sort.

Does $this really need to be changed? Else you are looking to rename the class. But first you need to find it.
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.

My Liveperson: http://liveperson.com/josh-connerty/
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 13
Reputation: Hugo Brand is an unknown quantity at this point 
Solved Threads: 0
Hugo Brand Hugo Brand is offline Offline
Newbie Poster

Re: Problem with $this

 
0
  #9
Aug 24th, 2009
Hi everyone. Thanks for the posts. I couldn't solve the problem.

Yes. I totally agree with the fact that this in most programming languages refers to object oriented code, but it doesn't look as if the author intended to use object oriented code within his example. If so, then I'm totally confused, because none of his previous code samples, even those that followed, demonstrated any form of object-orientation programming inside of PHP.

Thanks again, maybe I'll figure it out someday.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC