3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Class FyndiqCSVFeedWriter generates CSV export feed */ class FyndiqCSVFeedWriter { { /** * @var array export column names */ private $header = array(); /** * @var array products for export */ private $products = array(); /** * @var array fields upon which `addslashes` will be applied */ private $slashFields = array( 'article-name', 'product-brand', 'product-title', 'product-description', ); /** * Apply field transformations * * @param array $product * @return array mixed */ private function processProduct($product) { foreach($this->slashFields as $field) { if (!empty($product[$field])) { $product[$field] = addslashes($product[$field]); } } return $product; } /** * Add product to the feed * * @param $product * @return bool */ public function addProduct($product) { if ($this->isValidProduct($product)) { $this->header = array_unique(array_merge($this->header, array_keys($product))); $this->products[] = $this->processProduct($product); return true; } return false; } /** * Flush the feed data to the stream * * @return bool */ public function write() { // Write header if (fputcsv($this->stream, $this->header) === false) { return false; } // Write data foreach ($this->products as $product) { $finalProduct = array(); foreach ($this->header as $column) { $finalProduct[] = isset($product[$column]) ? $product[$column] : ''; } if (fputcsv($this->stream, $finalProduct) === false) { return false; } } unset($this->header); unset($this->products); return true; } }
Output for 5.4.0 - 5.4.40, 5.5.24, 5.6.8
Parse error: syntax error, unexpected '{', expecting function (T_FUNCTION) in /in/uM4m1 on line 8
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '{', expecting T_FUNCTION in /in/uM4m1 on line 8
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '{', expecting T_FUNCTION in /in/uM4m1 on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/uM4m1 on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected '{', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/uM4m1 on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/uM4m1 on line 8
Process exited with code 255.

preferences:
226.26 ms | 1395 KiB | 132 Q