[STDERR] PHP Fatal error now in php8

By: Corey Lee | Asked: 02/06/2023
ForumsCategory: Code Help[STDERR] PHP Fatal error now in php8
Corey Lee asked 2 years ago
Hi there, My following code had been working fine until I upgraded PHP to version 8: $entry = FrmProEntriesController::show_entry_shortcode(array( 'id' => $entry_ids[$i][item_id], 'format' => 'array'));   The warning is listed below. [STDERR] PHP Fatal error:  Uncaught Error: Undefined constant "item_id" in /home/.................   Would you please provide some insight? I really appreciate any help you can provide. Best, Corey 
2 Answers
Victor Font answered 2 years ago

The error says that the item_id word in that code is being seen as a constant and not a variable. While the code snippet is useful, it doesn't tell us much without the backtrace to find out the location of the code that is causing the fatal error. I run Formidable every day in my development environment built with PHP/8.2.1 and Formidable has no problems. Even though I doubt it's a problem with Formidable and more likely some custom code snippet, are you on the latest version of Formidable? What code is causing the problem? You should be able to see a backtrace in you server's PHP error log.

Corey Lee replied 2 years ago

WOW. Thanks a lot. I never thought of it. Sorry for this amateur question given I am not a programmer myself. I kind of copied and pasted it about 7 years ago from the web and it worked fine until PHP8. I am posting all of my code below. Maybe you can help to take a look at it. Many thanks in advance.

Corey Lee answered 2 years ago

This is the code snippet (old). Where did I do wrong? I am totally blind. xD  I believe this is the code that causes the issue, where item_id is not defined-the last line. ([STDERR] PHP Fatal error:  Uncaught Error: Undefined constant "item_id" in /home/elightin/domains/elearnready.app/public_html/wp-content/themes/woodmart-one/single-class-profile.php:106)

$entry_table = $wpdb->prefix."frm_item_metas";
$entry_ids = $wpdb->get_results ( "SELECT item_id FROM $entry_table WHERE meta_value ='$sid' and field_id = '9'");
$entry_ids = json_decode(json_encode($entry_ids), True);
$x = count($entry_ids) - 1;
$entry = array();
for($i = $x; $i >= 0; $i--)
{
	$entry = FrmProEntriesController::show_entry_shortcode(array( 'id' => $entry_ids[$i][item_id], 'format' => 'array'));
}

 

Victor Font replied 2 years ago

This code doesn't tell us anything. The error message says the error is coming from custom theme code: single-class-profile.php on line 106. It's not Formidable related. Please use pastebin or gist to post the entire single-class-profile.php file. Then come back and post a link to the patebin or gist.

We need to be able to see where item_id is being instantiated, if at all. Can you view the value of the $entry_ids variable? If item_id is meant solely as an array element key, you may just need to wrap item_id in straight quotes like this 'item_id'.

Corey Lee replied 2 years ago

Thank you so much. I would never "guess" this solution (as you can see, I am not a programmer). Your suggestion fixed the issue! Can I buy you a cup of coffee?

Victor Font replied 2 years ago

Coffee's not necessary, thank you. Enjoy being part of this community.

Corey Lee replied 2 years ago

I am glad that you are part of this community! Thanks again.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right