Friso Kluitenberg
Friso Kluitenberg

Reputation: 1179

PHP: Function Called empty

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 :)

Upvotes: 0

Views: 133

Answers (4)

fred727
fred727

Reputation: 2834

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.

Upvotes: 1

Milan Chheda
Milan Chheda

Reputation: 8249

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.

Upvotes: 3

FreedomPride
FreedomPride

Reputation: 1102

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

Upvotes: 0

Ahmet Karabulut
Ahmet Karabulut

Reputation: 153

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.

Upvotes: 0

Related Questions