hollyosburn Posted June 13, 2022 Share Posted June 13, 2022 My website is down with a fatal error. I know just the tiniest bit about coding, and found the error log. I know the line that is causing a fatal error, but don't know where to put parenthesis to fix. If someone could help me with this, I would be very grateful. This is the error: PHP Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` Here is the line the log says has the problem: $coronavirus_notice_banner_color = (@$_POST['action']=='save_coronavirus_notice_plugin') ? $coronavirus_notice_banner_color : (get_option('coronavirus_notice_banner_color')) ? esc_html(get_option('coronavirus_notice_banner_color')) : '#CC0000'; There are a few lines just like the one above that probably have the same issue, but if I can get some help on the one above, I think I can follow the pattern and fix the others. Thank you in advance! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 13, 2022 Share Posted June 13, 2022 I believe it is telling you that the complex statement that someone wrote there is no longer supported (if it ever was). Putting 2 of these comparisons together is silly coding in my book just to supposedly save some coding space or whatever. But it is difficult to re-interpret when you come back to it 3 months later. It also seems to be very incorrect. (Are you sure you copied it correctly?) To explain. The first that has the POST in it is a test against a string value. It is true then you are returning the value of the 'banner color' to the result var, which IS that same value. If it is not true then you are doing another (similar) test of the result of a call to getoption which if it returns a true value will return the value of a call to the esc_html function but if it is not true will simply return a color value (#cc0000). To put it in a different way: if ($_POST['action'] == 'save_corona_virus_notice_plugin') $coronavirus_notice_banner_color = $coronavirus_notice_banner_color; elseif(get_option('coronavirus_notice_banner_color')) $coronavirus_notice_banner_color = esc_html(get_option('coronavirus_notice_banner_color')); else $coronavirus_notice_banner_color = '#CC0000'; I don't see a parens problem here. But I see some highly unnecessarily complex variable names. Way too much typing. Quote Link to comment Share on other sites More sharing options...
hollyosburn Posted June 13, 2022 Author Share Posted June 13, 2022 4 minutes ago, ginerjm said: I believe it is telling you that the complex statement that someone wrote there is no longer supported (if it ever was). Putting 2 of these comparisons together is silly coding in my book just to supposedly save some coding space or whatever. But it is difficult to re-interpret when you come back to it 3 months later. It also seems to be very incorrect. (Are you sure you copied it correctly?) To explain. The first that has the POST in it is a test against a string value. It is true then you are returning the value of the 'banner color' to the result var, which IS that same value. If it is not true then you are doing another (similar) test of the result of a call to getoption which if it returns a true value will return the value of a call to the esc_html function but if it is not true will simply return a color value (#cc0000). To put it in a different way: if ($_POST['action'] == 'save_corona_virus_notice_plugin') $coronavirus_notice_banner_color = $coronavirus_notice_banner_color; elseif(get_option('coronavirus_notice_banner_color')) $coronavirus_notice_banner_color = esc_html(get_option('coronavirus_notice_banner_color')); else $coronavirus_notice_banner_color = '#CC0000'; I don't see a parens problem here. But I see some highly unnecessarily complex variable names. Way too much typing. Thank you so much for responding. Here is more of the code. I think I copied it correctly? What can I do to get around the fatal error? Is there a way to fix the parens so that it matches the Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` requirement that the error message says is the problem? Quote Link to comment Share on other sites More sharing options...
Solution ginerjm Posted June 13, 2022 Solution Share Posted June 13, 2022 (edited) As I said first thing -- the style of this code is not allowed at all. It has to be re-written. These new lines are not the same as the one you have the error on. They do not follow the same format as the bad one. I have no idea what the app is supposed to do for you but it is written rather tediously and I would have definitely found another way to do this that the mind-numbing way that the original code chose. I'm guessing that he/she too was a noob when writing it. Try this: $coronavirus_notice_banner_color = @$_POST['action']=='save_coronavirus_notice_plugin' ? $coronavirus_notice_banner_color : (get_option('coronavirus_notice_banner_color') ? esc_html(get_option('coronavirus_notice_banner_color')) : '#CC0000'); And I really don't like the use of the @ in this code. It is not a good practice. Edited June 13, 2022 by ginerjm 1 Quote Link to comment Share on other sites More sharing options...
hollyosburn Posted June 13, 2022 Author Share Posted June 13, 2022 (edited) The line that I have the error on is line 155. I appreciate any help you can give me. This is my wordpress website. Thank you for the updated code. It seems to work! The website is still a mess, but at least it's back up. Edited June 13, 2022 by hollyosburn changed to accept above code as solution! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 13, 2022 Share Posted June 13, 2022 Now study the difference in the original 'bad' line and the new line I gave you. Compare that to the syntax that the error message showed you and note how the parens have to be placed. Did you just move a parens on that line, causing this issue? Quote Link to comment Share on other sites More sharing options...
maxxd Posted June 14, 2022 Share Posted June 14, 2022 Not to mention WP's get_option() function allows a default in it's signature so the entire convoluted second ternary isn't necessary. $coronavirus_notice_banner_color = (!empty($_POST['action']) && $_POST['action'] == 'save_coronavirus_notice_plugin') ? $coronavirus_notice_banner_color : esc_html(get_option('coronavirus_banner_color', '#cc0000')); Either way, did you recently update your version of PHP or is this a recent plugin addition to your site? The way it's set up isn't supported anymore - PHP used to do it's best to figure out import in nested ternary operations, but it doesn't now. It needs to be explicit by way of parenthesis. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.