| | |
Problem with $this
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2007
Posts: 13
Reputation:
Solved Threads: 0
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:
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.
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:
PHP Syntax (Toggle Plain Text)
$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.
•
•
Join Date: Apr 2008
Posts: 53
Reputation:
Solved Threads: 10
•
•
•
•
I have studied this line of code and would like to know if $this has some sort of special meaning in PHP?
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
•
•
Join Date: Apr 2008
Posts: 53
Reputation:
Solved Threads: 10
To clarify, does the line
appear within something like the following
PHP Syntax (Toggle Plain Text)
$this = $parts[$x];
PHP Syntax (Toggle Plain Text)
class NameOfTheObject { }
•
•
Join Date: Nov 2007
Posts: 13
Reputation:
Solved Threads: 0
•
•
•
•
To clarify, does the line
appear within something like the followingPHP Syntax (Toggle Plain Text)
$this = $parts[$x];
PHP Syntax (Toggle Plain Text)
class NameOfTheObject { }
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.
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"
Please post your current document in [code=php] tags.
$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/
My Liveperson: http://liveperson.com/josh-connerty/
•
•
Join Date: Nov 2007
Posts: 13
Reputation:
Solved Threads: 0
Josh Connerty
This reply contains the original code in respect to the author who developed it, that I was studying.
}
?>
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
This reply contains the original code in respect to the author who developed it, that I was studying.
PHP Syntax (Toggle Plain Text)
<? // define some constants // message types $type = array("text", "multipart", "message", "application", "audio", "image", "video", "other"); // message encodings $encoding = array("7bit", "8bit", "binary", "base64", "quoted-printable", "other"); // parse message body function parse($structure) { global $type; global $encoding; // create an array to hold message sections $ret = array(); // split structure into parts $parts = $structure->parts; for($x=0; $x<sizeof($parts); $x++) { $ret[$x]["pid"] = ($x+1); $this = $parts[$x]; // default to text if ($this->type == "") { $this->type = 0; } $ret[$x]["type"] = $type[$this->type] . "/" . strtolower($this->subtype); // default to 7bit if ($this->encoding == "") { $this->encoding = 0; } $ret[$x]["encoding"] = $encoding[$this->encoding]; $ret[$x]["size"] = strtolower($this->bytes); $ret[$x]["disposition"] = strtolower($this->disposition); if (strtolower($this->disposition) == "attachment") { $params = $this->dparameters; foreach ($params as $p) { if($p->attribute == "FILENAME") { $ret[$x]["name"] = $p->value; break; } } } } 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.
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.
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/
My Liveperson: http://liveperson.com/josh-connerty/
•
•
Join Date: Nov 2007
Posts: 13
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- Problem with Windows Update and WinXP (Web Browsers)
- Installing Windows 98 On VMware. Floppy problem (Windows 95 / 98 / Me)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Problem with T720 (Cellphones, PDAs and Handheld Devices)
- Connection Problems (Networking Hardware Configuration)
- Encoding (Unicode) problem in IE 6.0 (Web Browsers)
- .htaccess mod_rewrite problem (Linux Servers and Apache)
- Javascript/HTML problem!!! (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: Parse error: syntax error, unexpected $end in /home/content/e/b/a/....
- Next Thread: user preferences
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube





