Search code examples
phplaravellaravel-4laravel-3

Laravel Framework: syntax error, unexpected 'function' (T_FUNCTION)


I'm trying to include a Macro in a fresh Laravel3 framework installation, I've got PHP 5.4 (phpinfo confirms this). I originally suspected it was an issue with closures not being support on 5.3.17, so I upgrade to 5.4 and I'm still getting this error.

Unhandled Exception

Message:

syntax error, unexpected 'function' (T_FUNCTION) Location:

C:\wamp\www\script-manager\application\libraries\macros\nav_link.php on line 3

Nav link file has the following macro:

<?php

HTML::macro('nav_link' function($route, $text) {
$class = ( URI::is($route) or URI::is($route.'/*') ) ? 'class="active"' : '';
$href  = URL::to($route);

$action = Request::route();
$action = $action->action;

if ( isset($action['as']) ) {
    $class = ( ($action['as'] == $route) or ($action['as'] == $route.'/*') ) ? 'class="active"' : '';
    $href  = URL::to_route($route);
}

return '<li ' . $class . '><a href="' . $href . '">' . $text . '</a></li>';
});

?>

And is being required at the bottom of start.php:

require path('app') . 'libraries\macros\nav_link.php';

I've literally found no one else with this problem under my circumstances, so I'm lost. Using WAMP 5.4 on Windows 7.

Thanks.


Solution

  • HTML::macro('nav_link' function($route, $text) {
    

    should be

    HTML::macro('nav_link', function($route, $text) {
                          ^ // You miss this comma