最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - syntax issue on php 7.4

programmeradmin3浏览0评论

I have a syntex issue on my WordPress platform since I tried to put php version on 7.4.

WordPress sent me automated email with the error below :

Error Details

An error of type E_PARSE was caused in line 12 of the file /public_html/wp-content/themes/bb-theme-child/companies.php. Error message: syntax error, unexpected 'fn' (T_FN), expecting '('

I put here the beginning of the file companies.php code and the line 12 is : function fn($function)

<?php

namespace DisplaceTech\Companies;

/**
 * Wrap function names for the namespace.
 *
 * @param string $function
 *
 * @return string
 */
function fn($function)
{
    return '\DisplaceTech\Companies\\' . $function;
}

/**
 * Add the Clients metabox to the Proposal page.
 */
function add_clients_metabox()
{
    $screens = ['page'];
    foreach ($screens as $screen) {
        add_meta_box(
            'clients',              // Unique ID
            __('Clients'),          // Box title
            fn('clients_box_html'), // Content callback, must be of type callable
            $screen,                // Post type
            'advanced',             // Context
            'high'                  // Priority
        );
    }
}
add_action('add_meta_boxes', fn('add_clients_metabox'));

NOTE: the platform works with php 7.3

I have a syntex issue on my WordPress platform since I tried to put php version on 7.4.

WordPress sent me automated email with the error below :

Error Details

An error of type E_PARSE was caused in line 12 of the file /public_html/wp-content/themes/bb-theme-child/companies.php. Error message: syntax error, unexpected 'fn' (T_FN), expecting '('

I put here the beginning of the file companies.php code and the line 12 is : function fn($function)

<?php

namespace DisplaceTech\Companies;

/**
 * Wrap function names for the namespace.
 *
 * @param string $function
 *
 * @return string
 */
function fn($function)
{
    return '\DisplaceTech\Companies\\' . $function;
}

/**
 * Add the Clients metabox to the Proposal page.
 */
function add_clients_metabox()
{
    $screens = ['page'];
    foreach ($screens as $screen) {
        add_meta_box(
            'clients',              // Unique ID
            __('Clients'),          // Box title
            fn('clients_box_html'), // Content callback, must be of type callable
            $screen,                // Post type
            'advanced',             // Context
            'high'                  // Priority
        );
    }
}
add_action('add_meta_boxes', fn('add_clients_metabox'));

NOTE: the platform works with php 7.3

Share Improve this question asked Apr 28, 2020 at 16:52 SamuelSamuel 3541 gold badge11 silver badges32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Option 1

Have you tried changing the function name? something similar function getClientFn($function){}? You can keep any name you want.

function getClientFn($function){
    return '\DisplaceTech\Companies\\' . $function;
}

function add_clients_metabox(){
    $screens = ['page'];
    foreach ($screens as $screen) {
        add_meta_box(
            'clients',              // Unique ID
            __('Clients'),          // Box title
            getClientFn('clients_box_html'), // Content callback, must be of type callable
            $screen,                // Post type
            'advanced',             // Context
            'high'                  // Priority
        );
    }
}
add_action('add_meta_boxes', 'add_clients_metabox');

Option 2: If you really need to keep 'fn' method, then give a try with below script which works in php 7.4.

$myfunction = fn($function) => '\DisplaceTech\Companies\\' . $function;

function add_clients_metabox(){
    $screens = ['page'];
    foreach ($screens as $screen) {
        add_meta_box(
            'clients',              // Unique ID
            __('Clients'),          // Box title
            $myfunction('clients_box_html'), // Content callback, must be of type callable
            $screen,                // Post type
            'advanced',             // Context
            'high'                  // Priority
        );
    } } add_action('add_meta_boxes', 'add_clients_metabox');

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论