skip to Main Content

I receive a weird error when testing a WordPress plugin I developed on my server.

I tested locally with PHP5.3.29 (PHPBrew) and PHP7. I get the following error

Parse error: syntax error, unexpected 'empty' (T_EMPTY), expecting identifier (T_STRING) in /home/arevicoc/sub_domains/fitmetfriso.nl/wp-content/plugins/wp-clickbank-vendor/core/Helper/Util.php on line 65

The function itself is rather simple (i get the error on the definition of the function

/**
 * Check if it is empty for a multi-dimensional array
 *
 * @param object $object
 * @param string $name
 * @return void
 */
public static function empty($object, $name){ // Line 65
    return empty(self::val($object,$name, null));
}

CPanel of the server I’ve been testing on lists ea-php55.

Why is this error occurring? I know empty is a function in PHP, but if inside a namespace, there shouldn’t be a conflict right? especially since it works in development.

Any reason why this use of reserved keywords as class function name is allowed in php 7?

Thank you in advance 🙂

4

Answers


  1. I am not sure but maybe you have to change your function’s name from empty to something else. It can be built-in function.

    Login or Signup to reply.
  2. Your issue is the function name itself.
    In PHP, there’s already a generic function called empty() . So overwriting is causing the issue.

    As per manual,
    http://php.net/manual/en/function.empty.php

    Login or Signup to reply.
  3. You cannot use empty() as your function name, because it’s a reserved keyword. Here is list of keywords, that you can’t use to define as your function names: http://php.net/manual/en/reserved.keywords.php

    From the documentation:

    You cannot use any of the following words as constants, class names,
    function or method names.

    Login or Signup to reply.
  4. empty is a reserved keyword you can not use for the name of a function :
    http://php.net/manual/en/reserved.keywords.php

    The doc says :

    You cannot use any of the following words as constants, class names, function or method names.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search