3v4l.org

run code in 300+ PHP versions simultaneously
<?php $product = false; $quantity = 1; $postedOptions = false; $downloads = false; $combine = false; //is this an item from a separate cart being combined? extract($data); if(is_int($product)) { $product = \CI::Products()->getProduct($product); if(!$product) { return json_encode(['error'=>lang('error_product_not_found')]); } //Clean up the product for the orderItems database $product = $this->cleanProduct($product); //get downloadable files $downloads = \CI::DigitalProducts()->getAssociationsByProduct($product->product_id); } $update = false; if(empty($product->hash)) { $product->hash = md5(json_encode($product).json_encode($postedOptions)); //set defaults for new items $product->coupon_discount = 0; $product->coupon_discount_quantity = 0; $product->coupon_code = ''; } else { if(!$combine) { //this is an update $update = true; } } $product->order_id = $this->cart->id; //loop through the products in the cart and make sure we don't have this in there already. If we do get those quantities as well $qty_count = $quantity; $this->getCartItems(); // refresh the cart items foreach($this->items as $item) { if(intval($item->product_id) == intval($product->product_id)) { if($item->hash != $product->hash) //if the hashes match, skip this step (this is an update) { $qty_count = $qty_count + $item->quantity; } } if($item->hash == $product->hash && !$update) //if this is an update skip this step { //if the item is already in the cart, send back a message return json_encode(['message'=>lang('item_already_added'), 'product_id'=>$product->product_id]); } } if(!config_item('allow_os_purchase') && (bool)$product->track_stock) { $stock = \CI::Products()->getProduct($product->product_id); if($stock->quantity < $qty_count) { return json_encode(['error'=>sprintf(lang('not_enough_stock'), $stock->name, $stock->quantity)]); } } if (!$quantity || $quantity <= 0 || $product->fixed_quantity==1) { $product->quantity = 1; } else { $product->quantity = $quantity; } //create save options array here for use later. $saveOptions = []; if(!$update && $product->product_id) // if not an update or non-product, try and run the options { //set the base "total_price" if($product->saleprice > 0) { $product->total_price = $product->saleprice; } else { $product->total_price = $product->price; } //set base "total_weight" $product->total_weight = $product->weight; $productOptions = \CI::ProductOptions()->getProductOptions($product->product_id); //option error vars $optionError = false; $optionErrorMessage = lang('option_error').'<br/>'; foreach($productOptions as $productOption) { // are we missing any required values? $optionValue = false; if(!empty($postedOptions[$productOption->id])) { $optionValue = $postedOptions[$productOption->id]; } if((int)$productOption->required && empty($optionValue)) { $optionError = true; $optionErrorMessage .= "- ". $productOption->name .'<br/>'; continue; // don't bother processing this particular option any further } if(empty($optionValue)) { //empty? Move along, nothing to see here. continue; } //create options to save to the database in case we get past the errors if($productOption->type == 'checklist') { if(is_array($optionValue)) { foreach($optionValue as $ov) { foreach($productOption->values as $productOptionValue) { if($productOptionValue->id == $ov) { $saveOptions[] = [ 'option_name'=>$productOption->name, 'value'=>$productOptionValue->value, 'price'=>$productOptionValue->price, 'weight'=>$productOptionValue->weight ]; $product->total_weight += $productOptionValue->weight; $product->total_price += $productOptionValue->price; } } } } } else //every other form type we support { $saveOption = []; if($productOption->type == 'textfield' || $productOption->type == 'textarea') { $productOptionValue = $productOption->values[0]; $productOptionValue->value = $optionValue; } else //radios and checkboxes { foreach($productOption->values as $ov) { if($ov->id == $optionValue) { $productOptionValue = $ov; break; } } $saveOption['value'] = $optionValue; } if(isset($productOptionValue)) { $saveOption['option_name'] = $productOption->name; $saveOption['price'] = $productOptionValue->price; $saveOption['weight'] = $productOptionValue->weight; $saveOption['value'] = $productOptionValue->value; //add it to the array; $saveOptions[] = $saveOption; //update the total weight and price $product->total_weight += $productOptionValue->weight; $product->total_price += $productOptionValue->price; } } } if($optionError) { return json_encode(['error'=>$optionErrorMessage]); } } //save the product $product_id = \CI::Orders()->saveItem((array)$product); //save the options if we have them foreach($saveOptions as $saveOption) { $saveOption['order_item_id'] = $product_id; $saveOption['order_id'] = $this->cart->id; \CI::Orders()->saveItemOption($saveOption); } if($update) { foreach($this->items as $key => $item) { if($item->id == $product_id) { $this->items[$key] = $product; } } } else { $product->id = $product_id; $this->items[] = $product; //update file downloads if($downloads) { foreach($downloads as $file) { \CI::Orders()->saveOrderItemFile(['order_id'=>$this->cart->id, 'order_item_id'=>$product->id, 'file_id'=>$file->file_id]); } } } //get current item count $itemCount = $this->totalItems(); if($update) { return json_encode(['message'=>lang('cart_updated'), 'itemCount'=>$itemCount]); } else { return json_encode(['message'=>lang('item_added_to_cart'), 'itemCount'=>$itemCount]); }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0070.01816.63
8.3.50.0070.01116.50
8.3.40.0070.00719.10
8.3.30.0040.01118.73
8.3.20.0060.00320.35
8.3.10.0090.00023.48
8.3.00.0080.00022.10
8.2.180.0070.01116.88
8.2.170.0120.00622.96
8.2.160.0070.00719.11
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0080.00019.39
8.2.120.0050.00326.35
8.2.110.0040.00422.25
8.2.100.0080.00317.84
8.2.90.0000.00819.21
8.2.80.0030.00518.05
8.2.70.0040.00417.63
8.2.60.0000.00817.93
8.2.50.0030.00618.10
8.2.40.0040.00420.67
8.2.30.0050.00320.91
8.2.20.0030.00518.22
8.2.10.0050.00218.23
8.2.00.0000.00718.17
8.1.280.0090.00625.92
8.1.270.0000.00822.27
8.1.260.0000.00826.35
8.1.250.0030.00628.09
8.1.240.0000.00920.91
8.1.230.0040.00719.20
8.1.220.0000.00817.78
8.1.210.0000.00918.77
8.1.200.0060.00317.47
8.1.190.0000.00817.35
8.1.180.0050.00318.10
8.1.170.0030.00518.70
8.1.160.0060.00319.05
8.1.150.0050.00218.95
8.1.140.0040.00419.58
8.1.130.0030.00518.96
8.1.120.0000.00717.59
8.1.110.0000.00717.37
8.1.100.0030.00517.57
8.1.90.0070.00017.55
8.1.80.0000.00717.53
8.1.70.0090.00017.56
8.1.60.0000.00817.54
8.1.50.0050.00317.63
8.1.40.0030.00517.55
8.1.30.0040.00417.85
8.1.20.0030.00517.76
8.1.10.0060.00317.75
8.1.00.0040.00417.66
8.0.300.0040.00420.16
8.0.290.0080.00016.72
8.0.280.0050.00318.42
8.0.270.0040.00417.23
8.0.260.0030.00316.90
8.0.250.0000.00716.98
8.0.240.0000.00717.07
8.0.230.0030.00517.09
8.0.220.0070.00017.05
8.0.210.0000.00716.93
8.0.200.0060.00016.99
8.0.190.0040.00417.06
8.0.180.0000.00817.00
8.0.170.0040.00417.06
8.0.160.0040.00817.04
8.0.150.0040.00416.92
8.0.140.0000.00717.00
8.0.130.0000.00613.41
8.0.120.0000.00716.88
8.0.110.0040.00416.93
8.0.100.0050.00317.04
8.0.90.0040.00417.02
8.0.80.0130.01017.04
8.0.70.0050.00216.82
8.0.60.0040.00416.91
8.0.50.0040.00417.00
8.0.30.0050.01117.31
8.0.20.0120.00717.40
8.0.10.0050.00317.25
8.0.00.0060.01216.86
7.4.330.0000.00515.55
7.4.320.0060.00016.73
7.4.300.0000.00716.76
7.4.290.0000.00816.72
7.4.280.0000.00916.75
7.4.270.0030.00316.71
7.4.260.0020.00516.72
7.4.250.0000.00816.49
7.4.240.0040.00416.77
7.4.230.0000.00816.62
7.4.220.0090.00916.65
7.4.210.0050.01016.60
7.4.200.0000.00716.47
7.4.160.0070.00916.63
7.4.150.0090.00917.40
7.4.140.0100.01017.86
7.4.130.0170.00316.45
7.4.120.0110.01016.71
7.4.110.0090.01316.63
7.4.100.0030.01316.71
7.4.90.0070.01016.66
7.4.80.0090.01219.39
7.4.70.0100.00716.49
7.4.60.0070.01016.78
7.4.50.0120.00616.88
7.4.40.0110.00816.68
7.4.30.0040.01316.63
7.4.00.0060.01014.96
7.3.330.0000.00513.23
7.3.320.0000.00513.28
7.3.310.0040.00416.43
7.3.300.0030.00316.37
7.3.290.0040.00416.42
7.3.280.0080.01016.37
7.3.270.0070.01517.40
7.3.260.0080.00916.39
7.3.250.0130.00716.53
7.3.240.0100.00816.58
7.3.230.0170.00316.64
7.3.210.0060.01316.58
7.3.200.0110.00716.41
7.3.190.0140.00316.42
7.3.180.0130.00316.59
7.3.170.0100.00716.56
7.3.160.0060.00916.46
7.3.120.0070.00915.13
7.3.110.0070.00914.78
7.3.100.0080.00614.98
7.3.90.0060.00814.73
7.3.80.0070.01014.94
7.3.70.0040.01114.94
7.3.60.0110.00614.63
7.3.50.0070.01014.92
7.3.40.0050.00814.83
7.3.30.0120.00314.97
7.3.20.0070.00916.76
7.3.10.0100.00616.63
7.3.00.0100.00716.73
7.2.330.0120.00616.75
7.2.320.0100.00716.86
7.2.310.0090.00916.71
7.2.300.0090.00916.70
7.2.290.0060.01016.69
7.2.250.0070.01015.05
7.2.240.0090.01115.17
7.2.230.0110.00515.27
7.2.220.0070.00815.25
7.2.210.0090.00415.08
7.2.200.0090.00315.26
7.2.190.0040.00715.26
7.2.180.0070.00815.13
7.2.170.0060.01115.10
7.2.80.0060.00616.57
7.2.60.0000.01516.80
7.2.00.0040.01519.35
7.1.330.0030.01115.90
7.1.320.0000.01215.86
7.1.310.0030.01015.88
7.1.300.0000.01015.58
7.1.290.0050.00915.93
7.1.280.0070.00715.56
7.1.270.0030.01515.69
7.1.260.0070.00415.61
7.1.200.0100.00315.80
7.1.100.0030.01017.99
7.1.70.0080.00917.09
7.1.60.0190.01235.17
7.1.50.0230.01334.91
7.1.40.0250.01234.30
7.1.30.0200.01934.36
7.1.20.0170.01434.53
7.1.10.0000.01916.45
7.1.00.0000.01716.75
7.0.200.0040.01416.54
7.0.190.0060.01016.79
7.0.180.0080.00816.18
7.0.170.0070.01016.11
7.0.160.0060.01016.27
7.0.150.0140.00816.18
7.0.140.0080.00816.21
7.0.130.0000.01616.50
7.0.120.0030.01816.41
7.0.110.0030.01416.36
7.0.100.0070.01116.28
7.0.90.0000.01716.38
7.0.80.0090.00916.56
7.0.70.0030.01116.10
7.0.60.0060.01016.25
7.0.50.0090.00916.24
7.0.40.0060.01616.38
7.0.30.0000.01516.51
7.0.20.0100.00716.38
7.0.10.0060.00916.36
7.0.00.0090.00616.36

preferences:
37.64 ms | 401 KiB | 5 Q