In PHP, is NULL a constant or a keyword?

Asked

Viewed 109 times

4

In PHP, NULL is a constant or a keyword?

I’ve heard it’s a constant, but it looks like the keyword behavior of PHP (that do not differentiate capital from minuscule)?

Example:

echo NULL;

echo null;

exit('teste');

EXIT('teste');

3 answers

6


NULL is a guy according to the documentation Link and is also the only possible value of the type NULL (but that’s what’s in the documentation)

So from the documentation it can be verified that NULL is:

  • a Guy.

    NULL is the only possible value of type NULL.

  • a constant.

    she was assimilated with the NULL constant.

  • a value.

    NULL is the only possible value of type NULL.

  • 1

    I know it may seem controversial some questions I ask, but do this test var_dump(array_key_exists('NULL', get_defined_constants())). The result is TRUE

  • Just to relax TRUE and FALSE are also constant, kkkkkkkk

  • It’s not really very confusing and ambiguous

  • 2

    NULL is a constant with the value NULL who’s kind NULL. :P

  • @Wallacemaxters very good example, this is very useful to get the result.

  • If you used the isset instead of array_key_exists, would return FALSE, for the isset checks if there is a variable and if it is NULL. (I hope I don’t confuse anyone with this placement)

Show 1 more comment

2

Only by complementing the reply from @Ricardo:

Keywords

Some represent things that look like functions, some seem constant but actually are not really: they are language constructors.

Examples of keywords:

  • Abstract
  • and
  • as
  • break
  • marry
  • Try
  • catch
  • const
  • continue
  • default
  • new
  • echo
  • Else
  • elseif
  • for
  • foreach
  • Function
  • global
  • instanceof
  • private
  • protected
  • public
  • Static
  • Return

Some that are also (but that actually look like functions)

  • die()
  • Empty()
  • isset()
  • unset()

To know all access to documentation.

-1

NULL in php is a type that represents the absence of value, in some languages it is represented by NIL!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.