Code snippets don't work with PHP 8.*

By: Markku Lehtola | Asked: 02/19/2023
ForumsCategory: General questionsCode snippets don't work with PHP 8.*
Markku Lehtola asked 2 years ago
Hi, this kind of stuff is not working anymore, because it's not supported in PHP 8.*. How to fix? add_action('frm_after_create_entry', 'create_csv', 30, 2); function create_csv($entry_id, $form_id) {
if ($form_id == 2) { //replace 1234 with the id of the form   br Markku
Rob LeVineRob LeVine replied 2 years ago

What is the error?

Victor Font replied 2 years ago

No closing braces?

Markku Lehtola replied 2 years ago

Critical error, whole site goes down. Braces are there, this is just part of the code, but since PHP 8 has not create_function, I think this too relates to creating functions...PHP 7.4 ok, 8.0 no go.

2 Answers
Walter JonesWalter Jones answered 2 years ago
Not a lot to go on here…but maybe try   
add_action('frm_after_create_entry', 'create_csv', 30, 2); 

function create_csv(int $entry_id, int $form_id): void {
    if ($form_id == 2) {
        // Your code for creating the CSV goes here
    }
}
 
Walter JonesWalter Jones replied 2 years ago

Are you trying to export from a view?

Markku Lehtola replied 2 years ago

"int"'s didn't help. Exporting directly from the form.

Victor Font answered 2 years ago
I don't see anything in the snippet that should cause PHP 8+ to fail. Have you enabled WordPress debug to get a detailed error message?
Markku Lehtola replied 2 years ago

It was after all: "ftp_put() expects parameter 1 to be resource, bool given in /home..."

Ok, this happens because ftp server is not online, but how to get something else than critical error/site down?

Tried this without luck:

if (($connect_it = ftp_connect($ftp_host)) !== false) {

$remote_file = $Client . "_" . $Project . "_" . $Product . "_" . $TimeStamp . ".csv";
if (ftp_put($connect_it, $remote_file, $local_file, FTP_BINARY)) {
//echo "WOOT! Successfully transfer $local_file\n";
} else {
echo "Doh! There was a problem, maybe server is offline...\n";
}
ftp_close($connect_it);

else { echo "noup";}
}

Victor Font replied 2 years ago

You're problem doesn't appear to have anything to do with Formidable. Formidable does not use ftp_put(). That looks like it may be custom code. You need to contact your server host to find out how to change your site's PHP error reporting.

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