1

I am having the following code in a php web page:

  if (bInserted) echo "abc";

I would expect PHP to give me a syntax error since I forget to add the dollar sign before the variable name. Howver, the page doesn't produce any errors. Instead, it even echoes the "abc" string. I am not really able to understand this.

2
  • 1
    Could you show the code of your page? Commented Oct 23, 2013 at 6:32
  • It should generate a PHP notice (but they may be supressed). Check your logs. Commented Oct 23, 2013 at 6:36

1 Answer 1

5

Your bInserted is interpreted as a constant and, since is not defined (I presume), it is then treated as the string "bInserted", which evaluates to true hence your "abc" is printed.

Anyway, such implicit conversion from constant to string should raise a notice, see the manual.

If you use an undefined constant, PHP assumes that you mean the name of the constant itself, just as if you called it as a string (CONSTANT vs "CONSTANT"). An error of level E_NOTICE will be issued when this happens.

If you really do not see any message, nor on screen nor in the logs, make sure you have set the correct error reporting level, you could for example try

ini_set('display_errors', 1);
error_reporting(E_ALL);

And, by the way, E_ALL is a defined constant in this case!

Sign up to request clarification or add additional context in comments.

3 Comments

It should produce notice so write something about enabling errors reporting ;)
Right! Will do it now :)
Than would be an option too :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.