11

For example, is the following program meaningful, and if so what should it print?

<?php
FuncTIon fOo($x) { eChO $x; }
FOO('bar');
IF (TRuE) { echO 'qux'; }
?>

My interpreter runs it and prints barqux, implying the keywords are not case-sensitive:

$ php case_sensitive_keywords.php 
barqux
$ php --version
PHP 5.5.7-1+sury.org~precise+1 (cli) (built: Dec 12 2013 21:37:40) 

However, this same question was asked last year, and the answers say that keywords are case-sensitive, in direct contradiction to what my PHP interpreter appears to tell me!

Community
  • 1
  • 1
jameshfisher
  • 34,029
  • 31
  • 121
  • 167
  • @JohnConde Is this really a duplicate? That question was about functions, this one asks about keywords. And the answer below goes above and beyond, detailing all the language elements. – Barmar Dec 17 '13 at 01:32
  • I think the question was closed simply because it was a silly question (you can easily answer it yourself by experiment, as you did), and "not constructive" was the closest available reason. It's not like PHP has an official specification separate from the implementation; there's just one implementation, and the language is whatever that implementation does. – Barmar Dec 17 '13 at 01:41
  • @jameshfisher [Meta] is the place to have discussions about specific questions and closures. I've edited out your comments from your question. I would also suggest you refrain from including swearwords in your comments and questions, as they may be deleted. – Duncan Jones Dec 17 '13 at 21:09
  • @Duncan, ah, I see. Thanks, I'll use that in future. (The "closed" notice could be clearer about this.) – jameshfisher Dec 18 '13 at 00:38

3 Answers3

19

Case sensitive (both user defined and PHP defined)

  • variables
  • constants
  • array keys
  • class properties
  • class constants

Case insensitive (both user defined and PHP defined)

  • functions
  • class constructors
  • class methods
  • keywords and constructs (if, else, null, foreach, echo etc.)
Ignacio Ocampo
  • 2,693
  • 1
  • 20
  • 31
8

No. Keywords are case-insensitive. Lerdorf et al., Programming PHP, page 17:

The names of user-defined classes and functions, as well as built-in constructs and keywords such as echo, while, class, etc., are case-insensitive. Thus, these three lines are equivalent:

echo("hello, world");
ECHO("hello, world");
EcHo("hello, world");
naglas
  • 462
  • 1
  • 6
  • 16
jameshfisher
  • 34,029
  • 31
  • 121
  • 167
  • Does it applies to namespaces too? I mean, are namespaces like 'Nspace\SubNamespace\SubSubNamespace' and 'nspace\subnamespace\subsubNamespace' and 'NSpace\SuBNameSpacE\SUBsuBNamesPACE' equivalent? – tonix Jan 29 '15 at 09:38
  • 1
    @tonix they are insensitive "internally" however if your filesystem is case-sensitive a PSR4 autoloader won't find incorrectly cased files, if they don't match the internal namespace or classname. It's a common problem when uploading code from Windows or Mac, to a Unix host. – scipilot Sep 15 '19 at 04:14
0
  1. No, Keywords are not case-sensitive.
  2. Class name & function name also not case-sensitive.
Paras Purwar
  • 1
  • 1
  • 2