3

See https://3v4l.org/6Oelk

var_export(array(NULL, TRUE, FALSE));

Result:

array (
  0 => NULL,
  1 => true,
  2 => false,
)

NULL is uppercase, but true and false are lowercase.

I suppose this has a historic reason, but I don't find it documented anywhere.


The following experiment is also quite interesting, and suggests that internally the "canonical" spelling of null, true and false is lowercase, contrary to what var_export() does: https://3v4l.org/ggM4E

define('false', '- false -');
define('FALSE', '- FALSE -');
define('null', '- null -');
define('NULL', '- NULL -');
var_export(array(TRUE, true, FALSE, false, NULL, null));

It shows that:

  • define('NULL', ..) and define('FALSE', ..) are allowed but have no effect in recent PHP versions.
  • define('null', ..) and define('false', ..) give a notice, but also have no effect in recent PHP versions.
  • In older PHP version (4.x), 'NULL' and 'FALSE' CAN be redefined and it does have an effect. But 'null' and 'false' cannot be redefined.

Oh, just for completeness: define('NULL', ..) and define('FALSE', ..) are actually NOT ignored if within a namespace, in PHP 5.x. See https://3v4l.org/JusvB. Or if you really want, you can even override 'null' and 'false' within a namespace: https://3v4l.org/i796C


Related: Uppercase Booleans vs. Lowercase in PHP, see this answer: https://stackoverflow.com/a/3807178/246724

Community
  • 1
  • 1
donquixote
  • 4,877
  • 3
  • 31
  • 54
  • Ok, I suspect maybe the answer is really boring. The person who wrote var_export() did not think much about it, and just thought that NULL looks better uppercase, even if it is inconsistent. And now we have to live with it, because otherwise, existing unit tests with hardcoded var_export() comparison would fail. Maybe someone has a better answer, but I'm afraid there might not be much more to it. – donquixote Dec 26 '15 at 05:48
  • If someone can confirm this explanation/theory of mine, ideally with some evidence / references, then this would be a valid and useful answer to this question. It may be boring, but it would mean people can stop looking. – donquixote Dec 26 '15 at 05:53
  • 1
    It is boring answer: https://github.com/php/php-src/blob/master/ext/standard/var.c#L436 (edit: updated link, somehow pasted wrong one) – Dukecz Dec 26 '15 at 17:00
  • Thanks @Dukecz ! git blame sends me here: https://github.com/php/php-src/commit/45f3322905dfa5ae60f7b5a55b8cb29d0ac63e5d Wonder if this was introduced here, or traces further back. (I don't know since when `var_export()` exists) – donquixote Dec 26 '15 at 17:49
  • 2
    @donquixote That's pretty much it, there is no special reason here. The particular choice of cases might make more sense if you consider that this code has been written by a C programmer, where (C99, stddef, stdbool) NULL is uppercase and true/false are lowercase. – NikiC Dec 26 '15 at 18:40
  • Ok, thanks. If someone wants to write this as an official answer, I am ready to mark it as accepted. – donquixote Dec 26 '15 at 18:48

1 Answers1

1

As @NikiC notes in the OP comments, there's no specific reasoning for this.

The most logical explanation though would be that considering PHP is written in C and historical standards define NULL as uppercase, and true, false as lowercase, reason follows that the standards in PHP would follow suit.

IEEE Std 1003.1 References:

oucil
  • 4,211
  • 2
  • 37
  • 53