-4

My friend, is able to run this without no errors:

$A = $_GET[a];

However, I am unable to run this get[] because it gives me this error message:

Use of undefined constant a - assumed 'a'

Is there a way I can change in the PHP settings that I can run the code like my friend can run this code?

Many thanks!

I understand that you have to write it this way:

$A = $_GET['a'];
jonprasetyo
  • 3,356
  • 3
  • 32
  • 48
  • 3
    If you understand what you are doing wrong, why do you want to do it anyway? – romainberger Apr 18 '13 at 15:08
  • 1
    possible duplicate of [What does the PHP error message "Notice: Use of undefined constant" mean?](http://stackoverflow.com/questions/2941169/what-does-the-php-error-message-notice-use-of-undefined-constant-mean) – Tommy Apr 18 '13 at 15:08
  • 1
    Short answer: No. Long answer: No, you cannot re-purpose built-in language constructs to get around your aversion to quotation marks. – Sammitch Apr 18 '13 at 15:14

3 Answers3

3

You can just turn off notices, but this is like ignoring the check engine light on your car...

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

You should be checking whether it's set...

$A = !empty($_GET['a']) ? $_GET['a'] : null;
Kermit
  • 33,827
  • 13
  • 85
  • 121
1

If a is supposed to be a string it should be surrounded by quotes. Otherwise PHP will assume it is a constant (since it doesn't have a $ in front of it) and in this case, it is not defined.

nullability
  • 10,545
  • 3
  • 45
  • 63
0

You have to define A as a constant if you want to use it as a constant. Turning off Error Reporting will only hide the errors... it still won't magically fix your code.

define("A", $_GET['a']);
AbsoluteƵERØ
  • 7,816
  • 2
  • 24
  • 35