programmierfrage.com
Ask a question    Sign Up Sign In
  • Train typing speed
  • About/Contact
  • Privacy Policy
  1. Home
  2. php - Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`

979 votes
2 answers

php - Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`

Get the solution ↓↓↓
This question already has answers here:

Undefined asked
2021-09-11
Write your answer



285
votes

Answer

Solution:

useold('parent_id') ?? $category['parent_id'] ?? ''

 {!! General::selectMultiLevel('parent_id', $categories, ['class' => 'form-control', 'selected' => old('parent_id') ?? $category['parent_id'] ?? '', 'placeholder'=>'---Chose Category---' ]) !!}
Write your answer




461
votes

Answer

Solution:

This issue is due to nested ternaries, which in my opinion is extremely difficult to read!

As the message states, avoid nested ternaries where precedence is not enforced by parenthesis.

From your code:

{!! General::selectMultiLevel('parent_id', $categories, [
'class' => 'form-control', 
'selected' => !empty(old('parent_id')) ? old('parent_id') : !empty($category['parent_id']) ? $category['parent_id'] : '', 
'placeholder'=>'---Chose Category---' ]) 
!!}

The issue lies within the 'selected' key. replacing

!empty(old('parent_id')) ? old('parent_id') : !empty($category['parent_id']) ? $category['parent_id'] : ''

with

!empty(old('parent_id')) ? old('parent_id') : (!empty($category['parent_id']) ? $category['parent_id'] : '')

Notice the additional parenthesis after the first :

But maybe consider using complete if statements for nested blocks for readability.

Write your answer




Share solution ↓

Additional Information:

Date the issue was resolved:
2021-09-11
Link To Source
Link To Answer People are also looking for solutions of the problem: cannot add or update a child row: a foreign key constraint fails

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Similar questions

Find the answer in similar questions on our website.

703 php - How to take jquery autocomplete values instead of labels? As well as guide me if I add dependence autocomplete?
18 javascript - AJAX File Upload using Codeigniter, jQuery shows the responce as "The action you have requested is not allowed"
158 javascript - when I pressed the login button without entering username & password, browser's top left corner display message like this "Invalid Info"
845 apache - PHP code is not being executed, but the code shows in the browser source code
99 php - Multiple table queries using Codeingiter active record does not give intended result
886 php - mysql update multiple tables, table 1 updates ok table 2 changes all values and ids
298 php - Can connect to database using mysqli, but cannot get even the simplest query to execute
63 How to get Php multidimensional array same key’s same value’s related total in new array?
869 php - Supplied resource is not a valid ldap result entry resource: ldap_get_attributes()
171 wordpress - Woocommerce archive-product.php overwrite not working with underscores.me theme

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.






About the technologies asked in this question

PHP

PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/



Welcome to programmierfrage.com

programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.

Get answers to specific questions

Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.

Help Others Solve Their Issues

Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.



Latest questions:

927 How to get Php multidimensional array same key’s same value’s related total in new array?

147 javascript - when I pressed the login button without entering username & password, browser's top left corner display message like this "Invalid Info"

628 php - Laravel Eloquent: Retrieve "second level" relationship entity

386 wordpress - Woocommerce archive-product.php overwrite not working with underscores.me theme

651 javascript - Laravel jQuery - Check if row exists in database

575 what's the best practice to long number in mysql and php

889 get unique records between two fields from mysql in php

191 File uploaded as blob format to My SQL through PHP has 0 byte

54 javascript - Ezpay : csrf token not allowed in header, Laravel application

996 How to check whether a file exists or not without knowing its directory in PHP?

Users questions:

NEW

Rename existing images with keyword in WordPress PHP

NEW

codeigniter

NEW

Class "web_profiler.controller.profiler" does not exist after upgrading symfony 3.4 to 4.4 version

NEW

$charge = \Stripe\Charge::create(array( "amount" => 100, "currency" => "gbp", "source" => $token, "destination" => [ "amount" => 20, "account" => 'xxxxx', ], ));

NEW

Write a PHP program that will generate the JSON structure below. Second Step: Write a JAVASCRIPT program that will parse the JSON structure once the PHP program is called using AJAX. You may show your output on the body of the HTML document or in the console




PHP x 410847
Laravel x 36785
Yii x 3846
CodeIgniter x 9997
Symfony x 7793
CakePHP x 3085
Zend Framework x 1235
Phalcon x 300
FuelPHP x 47
Slim x 570
JavaScript x 36883
React x 550
Angular x 1121
Vue.js x 181
JQuery x 11108
Backbone.js x 21
Node.js x 463
Ember.js x 10
Meteor x 7
Polymer x 20
Aurelia x 1
MySQL x 39074
CSS x 2497
Bootstrap x 1603
Foundation x 84
UIkit x 4
Semantic UI x 2
Bulma x 2
Animate.css x 1
HTML x 20978



© 2021-2023 Programming problem solving site for beginners and advanced. Answers to questions related to coding.

E-mail: [email protected]

This site uses cookies. We use them to improve the performance of our website and your interaction with it. Confirm your consent by clicking OK


OK