+ 3

PHP constant error

https://code.sololearn.com/w2zJh1wPBMqf/?ref=app This code have error, Any one help me and explain What is the reason for error.....

13th Jul 2020, 6:34 PM
Manimaran K
Manimaran K - avatar
6 Respostas
+ 5
Manimaran K As Igor Makarsky mentioned, you'll need to use the define function to create a constant from another variable value at runtime: In your case, replace the line: const word1 = $name; with: define("word1", $name);
14th Jul 2020, 6:08 PM
David Carroll
David Carroll - avatar
+ 16
Why do you need to assign a variable to a constant? You can use define() instead.
14th Jul 2020, 5:37 PM
Igor Makarsky
Igor Makarsky - avatar
+ 15
You can't assign a variable to a class constant, because the value must be a constant expression, not (for example) a variable, a property, or a function call.  See more: https://www.php.net/manual/en/language.oop5.constants.php
13th Jul 2020, 6:57 PM
Igor Makarsky
Igor Makarsky - avatar
+ 5
in php you cant initialize a constant variable with any other variable...but const can initialize another const...
13th Jul 2020, 7:00 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 3
Thank you all 🔥
15th Jul 2020, 6:15 AM
Manimaran K
Manimaran K - avatar
+ 2
Nice answers....But how can i achieve this process 😣☹️
14th Jul 2020, 4:37 AM
Manimaran K
Manimaran K - avatar