close

[solved] Undefined constant error in php 7.2

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Undefined constant error in php 7.2 in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Undefined constant error in php 7.2 Error Occurs?

Today I get the following error Undefined constant error in php 7.2 in php.

How To Solve Undefined constant error in php 7.2 Error ?

  1. How To Solve Undefined constant error in php 7.2 Error ?

    To Solve Undefined constant error in php 7.2 Error It's recommended to run it for your project on DEV first, check functionality and then push to LIVE.

  2. Undefined constant error in php 7.2

    To Solve Undefined constant error in php 7.2 Error It's recommended to run it for your project on DEV first, check functionality and then push to LIVE.

Solution 1

In addition, for those who are new to wordpress Plugin development and cant seem to figure out what it means to define “Constant” before its used…

Here is an example of what will throw an error:

add_action('wp_enqueue_scripts', myprefix_load_styles);

Declaring a function directly like that in a hook is one way to generate an error like this. Instead:

add_action('wp_enqueue_scripts', 'myprefix_load_styles');

Note, the function name is now inside the quotes. And that should work, if thats your scenario.

Solution 2

I’ve just created a PHP job to recursively clean up all files in a PHP project and automatically quote all strings which are undefined constants used inside square brackets for the array syntax.

Observation: this fix only targets array usage like $a[key1] which will be automatically transformed into $a[‘key1’]. The clean up process DOES NOT parse and compute a list of defined constants in your project, in order to white-list them for usage without quotes in all possible contexts.

It’s recommended to run it for your project on DEV first, check functionality and then push to LIVE.

QUICK USAGE:

git clone https://github.com/eyroot/lx-utils lx-utils
cd lx-utils && composer install --no-dev

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment