You are on page 1of 10

Language Basics

Lexical structure
• The set of basic rules that governs how you
write programs in that language.
• It is the lowest-level syntax of the language
• Specifies such as
– what variable names look like,
– what characters are used for comments,
– and how program statements are separated from
each other.
• Case Sensitivity
– 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
– Variables, on the other hand, are case-sensitive
• A statement
– A statement is a collection of PHP code that does something

• Use of semicolon in PHP


if ($needed) {
echo "We must have it!"; // semicolon required here
} // no semicolon required here

<?php
if ($a == $b) { echo "Rhyme? And Reason?"; }
echo "Hello, world" // no semicolon required before closing tag
?>
• Whitespaces and line breaks
– Whitespace doesn’t matter in a PHP program

• Comments
– Shell style comments (# )
(Unix shell scripting Languages)
– C++ comments (// )
– C comments (/* */)
• Literals
– A literal is a data value that appears directly in a
program
• Identifiers
– In PHP, identifiers are used to name variables,
functions, constants, and classes.
• Keywords
– A word reserved by the language for its core
functionality—you cannot give a variable,
function, class, or constant the same name as a
keyword. Case insensitive in PHP.
Operators and Expressions
• Operands
• Precedence
• Associativity
• Implicit casting
• Arithmetic Operator
– Arithmetic negation
– Arithmetic assertion
• String concatenation
• Auto increment and auto decrement
• Comparison operator

You might also like