Fatal Error Cannot Re-assign $this Php5
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business fatal error cannot re assign auto global variable _post Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Php Fatal Error Cannot Re Assign Auto Global Variable _post
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up PHP Fatal error: Cannot re-assign $this up vote 5 down vote favorite I get this error from my script: [Fri Apr 23 10:57:42 2010] [error] [client 10.0.0.1] PHP Fatal error: Cannot re-assign $this in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\abp\\fol\\test.php on line 27, referer: http://abp.bhc.com/fol/ Here is the code which produces the error: array( 'title' => 'Title', '1' => array( 'Title' => 'Title2', 'Link' => 'http://...', ), '12' => array( 'Title' => 'Title3', 'Link' => 'http://...', ) ), '1070453' => array( 'title' => 'Title4', '1' => array( 'Title' => 'Title5', 'Link' => 'http://...', ) ) ); $last = 0; //$this = 0; echo "
- \n"; foreach ($voiceboxes as $key => $value) { $last = 0; $this = null; //Error is thrown here, Line 27 //$voiceboxes[$key]['title'] echo "
- $value2\n"; } else { $this = (int) $key2; if ($this == $last + 1) { echo '
- '; } else { '
- ';} $last = $key2; echo $voiceboxes[$key][$key2]['Title'] . "
" . $voiceboxes[$key][$key2]['Link'] . '' . "\n"; } } echo "
- \n"; foreach ($value as $key2 => $value2) { if ($key2 == 'title') { echo "
UTC Votes:7 Avg. Score:4.7 ± 0.7 Reproduced:7 of 7 (100.0%) Same Version:7 (100.0%) Same OS:7 (100.0%) From: pacha dot shevaev at gmail dot com Assigned: dmitry Status: Closed Package: Scripting Engine problem PHP Version: 5.* OS: * Private report: No CVE-ID: View Add Comment Developer Edit [2005-09-03 13:36 UTC] pacha dot shevaev at gmail dot com Description: ------------ PHP 5.1RC1 throws fatal error when some variable gets assigned with $this by reference. However there's a workaround for this fatal error which is very simple: using a helper function which simply returns the passed argument by reference. I'm a bit lost http://stackoverflow.com/questions/2699587/php-fatal-error-cannot-re-assign-this here - what is the expected behavior? Yes, it may seem a bit weird to assign objects by reference in PHP5 but if you keep your code base PHP4 compatible you know what i mean. Reproduce code: --------------- test(); } https://bugs.php.net/34358 function test() { echo 'test'; } } $foo = new Foo(); ?> Expected result: ---------------- test Actual result: -------------- Fatal error: Cannot re-assign $this Patches Add a PatchPull Requests Add a Pull RequestHistoryAllCommentsChangesGit/SVN commitsRelated reports [2005-09-03 13:41 UTC] helly@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Objects are already references in PHP 5, thuse there is no sense in ...&$this in any way. [2005-09-15 13:37 UTC] pacha dot shevaev at gmail dot com I still find it a bug. I need a reference to $this for BC with PHP4 in the following piece of code: function &getRootDataSource() { $root =& $this; while ($root->parent != NULL) { $root =& $root->parent; } return $root; } [2005-09-15 14:27 UTC] sniper@php.net NOTE: This is about PHP 5. It might have worked in PHP 4 but it does not and will not work in PHP 5. [2005-09-15 15:23 UTC] pacha dot shevaev at gmail dot com I'm not an expert in PHP internals but there's a guy(stereofrog) on the SitePoint forum who has a different point of view(http://www.sitepoint.com/forums/showpost.php?p=214630
Detected You currently have javascript disabled. Several functions may not work. Please re-enable javascript to access full functionality. php4 to https://forums.phpfreaks.com/topic/224981-php4-to-php5-conversion-cannot-re-assign-this/ php5 conversion: Cannot re-assign $this Started by mikehoy, Jan 19 2011 05:15 http://www.loadedcommerce.com/community/forums/topic/fatal-error-cannot-re-assign-this-in/ PM This topic is locked 6 replies to this topic #1 mikehoy mikehoy Newbie New Members 3 posts LocationMinneapolis MN Posted 19 January 2011 - 05:15 PM I am trying to convert a php4 app to php5 and am getting this error (Fatal error: Cannot re-assign $this fatal error 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 fatal error cannot 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 Back to top #2 Maq Maq Advanced Member Administrators 9,406 posts LocationPennsylvania, USA Posted 19 January 2011 - 05:36 PM (I put [code][/code] tags in for you, please use them next time) tjmothy ini_set ("display_errors", "1"); error_reporting(E_ALL); Back to top #3 AbraCadaver AbraCadaver Creepy Ass Cracka Memba Gurus 1,893 posts LocationThe Republic of Texas Posted 19 January 2011 - 06:16 PM You can't use $this as a variable name, it is reserved: $something_else = $th
Vendor Shipping B2B and Wholesaler Store Services Customization Services Ecommerce Web Hosting Accept Online Payments Marketplace Featured Listing Experts Solutions Web Hosts Community Forums Issue Tracker Github Download Demos Store Login Sign Up Login Sign Up Blog Features Comprehensive Catalog and Shopping Cart Power Selling Features Data Driven Inventory Management Digital Downloads Affiliate Marketing Program Multi Vendor Shipping B2B and Wholesaler Store Services Customization Services Ecommerce Web Hosting Accept Online Payments Marketplace Featured Listing Experts Solutions Web Hosts Community Forums Issue Tracker Github Download Demos Store "Fatal error: Cannot re-assign $this in …" Home › Forums › Community General Support › Install & Config › "Fatal error: Cannot re-assign $this in …" This topic contains 4 replies, has 0 voices, and was last updated by cvkey 11 years, 5 months ago. Author Posts May 9, 2005 at 3:29 pm #7982 cvkeyParticipant This message occurs in browser after installing… "Fatal error: Cannot re-assign $this in …/public_html/cre/admin/includes/classes/upload.php on line 31" Here is some of the code: class upload { var $file, $filename, $destination, $permissions, $extensions, $tmp_filename, $message_location; function upload($file = ", $destination = ", $permissions = ‘777', $extensions = ") { $this->set_file($file); $this->set_destination($destination); $this->set_permissions($permissions); $this->set_extensions($extensions); $this->set_output_messages(‘direct'); if (tep_not_null($this->file) && tep_not_null($this->destination)) { $this->set_output_messages(‘session'); if ( ($this->parse() == true) && ($this->save() == true) ) { return true; } else { // self destruct $this = null; ******this is line 31********** return false; } } } function parse() { global $messageStack; if (isset($_FILES[$this->file])) { $file = array(‘name' => $_FILES[$this->file], ‘type' => $_FILES[$this->file], ‘size' => $_FILES[$this->file], ‘tmp_name' => $_FILES[$this->file]); } elseif (isset($GLOBALS[$this->file])) { global $HTTP_POST_FILES; Here are more details: Using ‘loaded61a.zip' uploaded (3 times) all in ASCII mode to public_html/cre/ CHMOD 777 2 of the configure.php s Created mysql db with persmissions set to ALL Ran install (all succeeded) step 7 displays two bu