Sachy Sachy - 3 months ago 9
PHP Question

Parsing Error on WebServer (live Server) and no Parsing Error on Local Machine

I developed and tested an application on my local machine.. everything works perfectly!
When I migrated this to a live server I keep getting all the parsing errors!!
For e.g

I don't know what is the error on the following code?

Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /home/content/index.php on line 126


Line 126 is line 3 (starting from items) below

<?php

$this->widget('bootstrap.widgets.TbCarousel',
array(
'items'=>array_map(function($record){
return array(

'image' => Yii::app()->baseUrl.'/'.CHtml::encode($record['file_location']),
'label'=>$this->renderPartial("_frontlabel",array('record'=>$record),true),
'imageOptions'=>array('style'=>'height: auto; max-height: 1000px; overflow:auto; max-width: 900px;margin-bottom: 0 auto;'),

'itemOptions' => array('class'=>'carousel-inner','style'=>'height:800px;margin-top:0px;margin-left:0px'),
'captionOptions'=>array('style'=>'background: none repeat scroll 0 0 rgba(0, 0, 0, 0.4);'),
'caption'=>$this->renderPartial("_frontCaptionContent",array('record'=>$record,'cc'=>new ECurrencyHelper()),true),

);
},$dataProvider->getdata()),


));
?>

Answer

This is because of you are using anonymous function in below line:

'items'=>array_map(function($record){
      return array(
      ...

This feature is available as of PHP version 5.3 and above. So you need to upgrade your server's PHP version to +5.3 or you should not use anonymous functions.