3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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; } }
based on uM4m1
Output for 5.0.0 - 7.2.0
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/rNqZ7 on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/rNqZ7 on line 12
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/rNqZ7 on line 12
Process exited with code 255.