Why there is fatal error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
8th Oct 2019, 7:45 PM
UraL
5 Answers
+ 5
Because you assigned an expression and it's not allowed. Static variable and properties may only be initialized using a literal or a constant.
8th Oct 2019, 7:57 PM
AZTECCO
AZTECCO - avatar
+ 3
AJ/AY yes, it works
8th Oct 2019, 8:08 PM
UraL
+ 3
Thanx
8th Oct 2019, 8:09 PM
UraL
+ 2
Because you used static keyword with variable and assigned to it's expression. You can use static to initialize the variable only. static also can be use with constant value and function. Put this and check again. <?php //$int = sqrt(100); static $int = 0; $int = sqrt(100); //fatal error echo $int; ?>
8th Oct 2019, 7:52 PM
A͢J
A͢J - avatar
+ 1
Welcome
8th Oct 2019, 8:11 PM
A͢J
A͢J - avatar