PHP Upgrade breaks broken code

Posted on Sunday 6 January 2008

finebynature had a nasty error message being displayed yesterday..


Fatal error: Cannot re-assign $this in /home2/finebyn/public_html/classes/cart.php on line 28

That was it, all that was displayed on the site.

My first thought was - I really should have provided a nice fallback page for fatal errors
Looking back at the offending line of code - i’m surprised it Ever worked in Any version of PHP.

class Cart() {
 
  function Cart() {
    session_start();
    if (empty($_SESSION[‘cart’])) {
      // init object and things..
      $_SESSION[‘cart’] = $this;
    }
    $this = $_SESSION[‘cart’];
  }
}

From within the objects constructor I was re-setting The Object that holds that constructor.
I fixed the problem by re-setting the properties of the object from those in the session and not the Whole object itself.


No comments have been added to this post yet.

Leave a comment

(required)

(required)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.


RSS feed for comments on this post | TrackBack URI