mikehoy Posted January 19, 2011 Share Posted January 19, 2011 I am trying to convert a php4 app to php5 and am getting this error (Fatal error: Cannot re-assign $this in ) when I call this class. $this = $this->createUnique($new); is the line that generates the error. I try to rename $this to $_this but it does not help. I think I lose the reference to the object later on in the code. Then I will get an error like (Fatal error: Call to a member function createUnique() on a non-object in) Is there another way to reference the current instance of an object in php5? Any help appreciated... Code Example: class imageobject{ var $handle; var $height=0; var $width=0; var $directory; var $filename; //constructor function imageobject($directory,$filename,$width=0,$height=0,$color="FFFFFF") { $this->directory = $directory; $this->filename = $filename; if ($filename=="" && $width>0 && $height>0){ $new = $this->createImage($width,$height); $this = $this->createUnique($new); }elseif (file_exists($directory.$filename)){ $size = GetImageSize($directory.$filename); if ($size) $this->handle = $this->getHandle($directory.$filename,$size[2]); $this->width = $size[0]; $this->height = $size[1]; } function createUnique($imgnew) { $this->type = substr($this->output,0,3); $unique_str = $this->uniqueName(); switch ($this->type){ case "png": imagepng($imgnew,RES_DIR.$unique_str); break; default: imagejpeg($imgnew,RES_DIR.$unique_str,$this->quality); break; } $this->handle && imagedestroy($this->handle); $newobject = new imageobject(RES_DIR,$unique_str,$this->type); return $newobject; } )//end class Link to comment https://forums.phpfreaks.com/topic/224981-php4-to-php5-conversion-cannot-re-assign-this/ Share on other sites More sharing options...
Maq Posted January 19, 2011 Share Posted January 19, 2011 (I put tags in for you, please use them next time) Link to comment https://forums.phpfreaks.com/topic/224981-php4-to-php5-conversion-cannot-re-assign-this/#findComment-1162022 Share on other sites More sharing options...
AbraCadaver Posted January 19, 2011 Share Posted January 19, 2011 You can't use $this as a variable name, it is reserved: $something_else = $this->createUnique($new); Link to comment https://forums.phpfreaks.com/topic/224981-php4-to-php5-conversion-cannot-re-assign-this/#findComment-1162052 Share on other sites More sharing options...
mikehoy Posted January 19, 2011 Author Share Posted January 19, 2011 I changed the variable name to $_this Then I get an error (Fatal error: Call to a member function createUnique() on a non-object in) in this line $new = $this->createImage($width,$height); Link to comment https://forums.phpfreaks.com/topic/224981-php4-to-php5-conversion-cannot-re-assign-this/#findComment-1162155 Share on other sites More sharing options...
ignace Posted January 19, 2011 Share Posted January 19, 2011 I changed the variable name to $_this Then I get an error (Fatal error: Call to a member function createUnique() on a non-object in) in this line $new = $this->createImage($width,$height); Maybe learn PHP first? AbraCadaver already told you how to solve the problem: You can't use $this as a variable name, it is reserved: $something_else = $this->createUnique($new); Link to comment https://forums.phpfreaks.com/topic/224981-php4-to-php5-conversion-cannot-re-assign-this/#findComment-1162159 Share on other sites More sharing options...
mikehoy Posted January 19, 2011 Author Share Posted January 19, 2011 I changed the variable name to $_this Then I get an error (Fatal error: Call to a member function createUnique() on a non-object in) in this line $new = $this->createImage($width,$height); Maybe learn PHP first? AbraCadaver already told you how to solve the problem: You can't use $this as a variable name, it is reserved: $something_else = $this->createUnique($new); Thanks AbraCadaver that did solve this issue... Link to comment https://forums.phpfreaks.com/topic/224981-php4-to-php5-conversion-cannot-re-assign-this/#findComment-1162196 Share on other sites More sharing options...
PFMaBiSmAd Posted August 8, 2012 Share Posted August 8, 2012 @Yasoymama, you need to start your own threads for your coding problems so that you can find and track your own threads. I have split your post in this thread into its own thread in this same forum section. Locking this thread... Link to comment https://forums.phpfreaks.com/topic/224981-php4-to-php5-conversion-cannot-re-assign-this/#findComment-1367809 Share on other sites More sharing options...
Recommended Posts