Fatal error Constant expression contains invalid operations

0 votes

I am getting an error:

Fatal error: Constant expression contains invalid operations in config.php on line 214

That line was:

 protected static $dbname = 'mydb_'.$appdata['id'];

Whether I did any mistakes in quotes? Or somewhere else?

My search for the error message only showed a different source cause (a dynamic default value in a function definition).

Nov 8, 2020 in PHP by kartik
• 37,510 points
17,262 views

1 answer to this question.

0 votes

Hello @kartik,

This is because a static variable contains a constant value in it. But in your case:

protected static $dbname = 'mydb_'.$appdata['id'];

$appdata['id'] is dynamic that can change its value during the execution. That's why the error is showing.

Hope it helps!!

answered Nov 8, 2020 by Niroj
• 82,880 points

Related Questions In PHP

0 votes
1 answer
0 votes
1 answer

Fatal error: Cannot access empty property in C:\xampp\htdocs\MyTestPages\f.php on line 15

Hello @kartik, You access the property in the ...READ MORE

answered Oct 19, 2020 in PHP by Niroj
• 82,880 points
1,523 views
0 votes
1 answer
0 votes
1 answer

Fatal error: Call to undefined function imap_open() in PHP

Hello @kartik, In Ubuntu for install imap use sudo ...READ MORE

answered Oct 29, 2020 in PHP by Niroj
• 82,880 points
5,122 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
21,874 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,678 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,540 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
41,714 views
0 votes
1 answer

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in .?

Hello @kartik, You may get this error because ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,880 points
2,080 views
0 votes
1 answer

Invalid argument supplied for foreach() on line 25. Error in my php and mysql

Hello @viven , This should be a simple fix ...READ MORE

answered Aug 4, 2020 in PHP by Niroj
• 82,880 points
3,880 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP