What's wrong with this code?
<?php
namespace DEMO;
class Config
{
const PRICE = $_GET['alim'];
}
Why I'm getting Error 500 for using $_GET['alim'] but If I use const PRICE = '100'; then It's Ok
What's wrong with this code?
<?php
namespace DEMO;
class Config
{
const PRICE = $_GET['alim'];
}
Why I'm getting Error 500 for using $_GET['alim'] but If I use const PRICE = '100'; then It's Ok
You can use only constant expressions in class constant definitions. You have to affect the value to Config::price
in the constructor.
<?php
namespace DEMO;
class Config
{
private $price;
public function __construct()
{
$this->price = $_GET['alim'];
}
}