# Need help with converting PHP5 class code to PHP4

**URL:** <https://forum.kirupa.com/t/need-help-with-converting-php5-class-code-to-php4/223320>\
**Category:** programming\
**Created:** [April 21, 2007, 7:11am UTC](https://forum.kirupa.com/t/need-help-with-converting-php5-class-code-to-php4/223320 "2007-04-21T07:11:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qgeis](https://avatars.discourse-cdn.com/v4/letter/q/76d3ee/32.png) [@Qgeis](https://forum.kirupa.com/u/Qgeis)\
**Post date:** [April 21, 2007, 7:11am UTC](https://forum.kirupa.com/t/need-help-with-converting-php5-class-code-to-php4/223320/1 "2007-04-21T07:11:59Z")

</div>

I’m not a programmer but a job at hand requires me to build something like a shopping cart with Ajax so I read some tutorials and got my hands dirty with Prototype.

Nothing wrong with the JS but the PHP that is returning the results seems to be written in PHP5 so it doesn’t work on my server (which has PHP4).

```php
<?php
session_start();

class Shopping_Cart {

    private $cart;

    function __construct($cart="") {
        $this->cart = $cart;
    }

    function getCart() {
        return $this->cart;
    }
   
    function addToCart($item) {
        if(isset($this->cart[$item])) {
            $this->cart[$item]++;
        } else {
            $this->cart[$item] = 1;
        }      
    }

    function deleteFromCart($item) {
        if(isset($this->cart[$item])) {
            $this->cart[$item]--;
            if($this->cart[$item] == 0) {
                unset($this->cart[$item]);
            }
        }
    }
   
}

$items = $_SESSION["cart"];

// Retrieve the parameters
$task = $_GET['task'];
$item = $_GET['item'];

if ($task == "add") {

   $cart->addToCart($item);
   $_SESSION["cart"] = $cart->getCart();
   echo "item added!";
   
} else {

   $cart->deleteFromCart($item);
   echo "item deleted!";
   
}
?>

```

The error displayed:

> **Parse error:** parse error, unexpected T\_STRING, expecting T\_OLD\_FUNCTION or T\_FUNCTION or T\_VAR or ‘}’ in /pathtomyscript/managecart.php on line 6

Line 6 is where it says [COLOR=“RoyalBlue”]private $cart[/COLOR]

I hope someone can be kind enough to show me how to turn the class into PHP4 code.
