-1

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

Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121
Abdul Alim
  • 110
  • 7

1 Answers1

2

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'];
    }
}
Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121