Is PHP Case sensitive? What are sensitive words in PHP?

0

Hypertext PreProcessor acronym PHP which was earlier known as the Personal Home Page (PHP) is widely used and well known server-side scripting language which is an alternative to the server-side scripting languages such as — Active Server Pages (ASP) and Java Server Pages (JSP).

PHP is used by many known social-networking websites which include Facebook and the blogging websites like WordPress. You must have raised the same question to your teachers, whether the PHP is a case sensitive programming language or not. If so, then what are the case sensitive words in PHP?

In this article I assist you all in clearing your doubt on — whether the PHP is a case sensitive language or not. Certainly, the PHP is not a case sensitive language, but in other hand it is neither case insensitive language since, it is comprised of both i.e. — PHP is a case sensitive as well as case insensitive language. It might be a bit confusing for most of you. So, let’s make it clearer with an example.

Case Sensitive Words in PHP

In PHP constants, variables, array keysclass constants and class properties are the case sensitive words and functions, whether it is a user defined or PHP system defined (i.e. — inbuilt).

Constants are Case sensitive

In PHP constants are similar to variables with two exceptions i.e. — once it is defined it cannot be changed or undefined.

For example to define a constant in PHP named “CITY”, we’ll use following PHP snippet

<?php
define("CITY","New Delhi"); //declaration and definition
echo CITY; // prints the value of CITY i.e. "New Delhi"
?> 

Here in this example constant CITY is case-sensitive which means calling it as city or City will be treated as different variable.

Variables are Case sensitive

In PHP variables starts with dollar sign ($) and are known as the containers which are used to store information. There are mainly three types of variables in PHP which include :

  1. Integer
  2. String
  3. Boolean

Similarly to the constants in PHP the variables are also case sensitive. Which means it should be used same as it is declared.

For example —

<?php
$COUNTRY="India" //string
$Country=91; // integer 
$country=True; // Boolean 
echo $COUNTRY; // Output: India 
echo $Country; // Output: 91
echo $country; // Output: True
?>

In the above example country variable is used with the three different data-types where each variable is used to store different value, but have same spelling.

Array keys are Case sensitive

Array_keys() is a special type of function used to access and manipulate arrays  in PHP. It supports simple and multi-dimensional arrays in PHP.

Same as variables and constants array_keys() are also case-sensitive.  For example —

<?php
$address=array("Country"=>"India","State"=>"New Delhi","CountryCode"=>"91");
print_r(array_keys($address));

$ADDRESS=array("Country"=>"USA","State"=>"CA","CountryCode"=>"1");
print_r(array_keys($ADDRESS));

?>

In the above example $address and $ADDRESS will be treated as two different arrays.

Class Constants are Case sensitive

As like in constants which let the user define a variable in the programme which cannot be changed or re-define, the class constants does the same function as constant in PHP.

Here in case of a constant class in PHP the entire class defined as the constant which remain same and unchanged as it is predefined by the user. For example —

<?php
class TestClass
{
    const UserName = "Isrg Rajan";
    const UserCity= "New Delhi";
}
echo "Name of the user: ". TestClass::UserName;
echo "City of the user: ". TestClass::UserCity;
?>

Here in case of constant class , class name and the object names are case sensitive.

Class Properties are Case sensitive

In PHP class properties are case sensitive and are also known as the attributes, and fields. The class properties are defined with one of the keywords from — public, private and protected followed by the normal variable deceleration procedure.

<?php
class UserInfo {
private $username="user@example.com";
private $userpwd="123456";
}

class userInfo {
private $Username="user@example.com";
private $Userpwd="123456";
}

?>

Here in the above example Classes UserInfo and userInfo will be treated two different classes  and thus its properties.

Case Insensitive Words in PHP

Case Insensitive also refereed as the “non sensitive” and “not sensitive” in most of the programming languages. In computer programming case insensitive words whether it is lower-case or upper case are interpreted and treated as the same words.

In PHP functions, class constructors and class methods are case insensitive where constructs and keywords like if, else, null, echo and foreach etc. are case insensitive.

Comments

Loading...