Php Literals

  • A literal is a data value that is directly written in the program.
  • For example – 2023, 3.140, Hello India, true, null, etc.

Php Identifiers

  • An identifier is simply a name of variables, functions, constants, classes, etc.
  • The first character of an identifier must be an ASCII letter (uppercase or lowercase), the underscore character (_), and then any of the characters including numbers from 0–9.

Php Comments

  • PHP supports both single-line (// as in C++ and # as in Perl or Linux or Unix) and multi-line (/* … */ as in C) comments.

Php Variables

  • In Php, variable names always begin with a dollar sign ($).
  • Php variables name does not include space and does not start with numbers.
  • Php variables are case-sensitive i.e., $VAL, $val, $Val, and $vAL are all different due to case sensitivity.

Php Keywords/Reserve words

  • A keyword is a unique word set by the language for its core functionality.
  • We cannot give a variable, function, class, constant name, etc. the same name as a keyword.
  • Keywords are case-insensitive.
  • Php keywords are: –

abstract, and, array(), as, break, callable, case, catch, class, clone, const, continue, declare, default, die(), do, else, else if, empty(), enddeclare, endfor, endforeach, endif, endswitch, endwhile, eval(), exit(), extends, final, finally, for, foreach, function, global, goto, if, implements, include, include_once, instanceof, interface, isset(), list(), namespace, new, or, print, private, protected, public, require, require_once, return, static, switch, throw, trait, try, unset(), use, var, while, xor, yield, yield from

Php Data Types

  • Php is a loosely typed language i.e., Php automatically associates a data type to the variable, when assigning a value. 
  • On the basis of data storage capacity, PHP has the following data types- 
    • Scalar data types

      • This data type stores only a single value.
      • Example of four scalar datatypes is – Integers, Floating-point numbers, Strings, and Booleans.
    • Compound/Collection/User Defined data types

      • This data type stores multiple values.
      • Example of two compound datatypes is – Arrays and Objects. 
    • Special data types

      • This data type stores special data values.
      • Example of two Special data types is Resource and NULL.
  • Integers
    • Integers are whole numbers with +ive or -ive values and typically range from −2,147,483,648 to +2,147,483,647.
    • Php has an in-built function known as is_int() to test whether the value is an integer or not. Its syntax is (is_int($value)). 
    • Integer literals include decimal, octal, binary, or hexadecimal values.
      • Decimal Integers/values are represented by a sequence of digits, without leading zeros. The sequence may begin with a plus (+) or minus (−) sign. If there is no sign, a positive is assumed. Examples of decimal integers may be:
        2023, −220, +58, etc.
      • Octal values are recognized by or consist of a leading 0 and a sequence of digits from 0 to 7. Octal numbers are prefixed with a plus or minus symbol. The weight of octal values is different from other integer values. Some examples of octal values are:
        0421, +035, -25, etc.
      • Hexadecimal values begin with 0x, followed by a sequence of digits (0–9) or letters (A–F) with + and – symbols. The letters can be upper- or lowercase but are usually written in capitals. Some examples of hexadecimal values are:
        0xAC, +0x36, –0xAC39 etc.
      • Binary numbers started with 0b, followed by a sequence of two digits (0 and 1) with + and – symbols. Some examples of Binary values are: 
        0b00001001, 0b01110011, -0b101 etc. 
  • Floating-Point/Real Numbers
    • Floating-point numbers are numeric values with decimal digits along with the +ive or -ive symbols. The value range is between 1.7E−308 to 1.7E+308 with 15 digits of accuracy. PHP recognizes floating-point numbers in two different formats – in Normal form and in Scientific notation form. The normal form of representation is – 3.141, 0.0001, -35.101, and in Scientific notation form is – 0.3141E2 equivalent to 0.3141*10^2 or 3.141; 36.01E-5 equivalent to 36.01*10^(-5). Php has an in-built function known as the is_float() function to test whether a value is a floating-point number or not. The syntax is (is_float($value)). 
  • Strings

Link for String Details

  • Booleans
    • A Boolean value is represented in two forms – True (1) and False (0).
    • Truthfulness and falseness are determined by the outcome of conditional code.
    • In PHP, the following values are used to evaluate False:
      The keyword False, The integer 0, The floating-point value 0.0, The empty string (“”) and the string “0”, An array with zero elements, The NULL value.
    • In Php, a value that is not false is true, including all resource values.
    • PHP provides true and false keywords for clarity of Boolean value.
    • The is_bool() function is used to test whether a value is a Boolean or not.
  • Arrays

Link for Array Details

  • Objects
    • PHP also supports object-oriented programming (OOP) features.
    • In OOPs, Classes are the building blocks of object-oriented design, and a class is a structure that contains properties (variables) and methods (functions). Once a class is defined, any number of objects can be made from it with the new keyword, and the object’s properties and methods can be accessed with the -> construct.
    • Use the is_object() function to test whether a value is an object. The syntax is (is_object($Object_name)). 
    • For example –
     class Student          //class creation
               function studetails()
               $stu_name = “John”;  
               echo “Student Name is : “ .$stu_name;  
     $obj1 = new Student();    //Object creation
     $obj1 -> studetails();       // Function calling
  • Resources
    • Resources data types are used to store some function calls or references to external PHP resources. For example – a database call during database connectivity. It is an external resource.
    • Each active resource has a unique identifier. Each identifier is a numerical index in an internal PHP lookup table that holds information about all the active resources. PHP maintains information about each resource in this table, including the number of references to (or uses of) the resource throughout the code. When the last reference to a resource value goes away, the extension that created the resource is called to perform tasks such as freeing any memory or closing any connection for that resource. The benefit of this automatic cleanup is best seen within functions when the resource is assigned to a local variable. When the function ends, the variable’s value is reclaimed by PHP.
    • When there are no more references to the resource, it’s automatically shut down.
  • NULL
    • Null is a special data type that has only one value: NULL. That value is available through the case-insensitive keyword NULL.
    • The NULL value represents a variable that has no value.
    • For example – $val=Null or $val=NULL or $val=null.
    • The is_null() function is used to test whether a value is NULL.
    • The syntax is (is_null($Variable_name)). 


Categories: Php Theory


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.