Saideepthi WT Notes
Saideepthi WT Notes
Web technologies refer to the tools, techniques, and frameworks used to create and
manage websites, web applications, and web-based services. They are the backbone
of the internet, enabling users to interact with content, services, and applications
online.
content updates.
3. Full-Stack Development
PHP Introduction
PHP is a server-side scripting language created primarily for web development but it
languages like JavaScript, which are executed on the user’s browser, PHP scripts run
on the server. The results are then sent to the client’s web browser as plain HTML.
development.
● It can be integrated with many databases such as Oracle, Microsoft SQL Server,
● It supports main protocols like HTTP Basic, HTTP Digest, IMAP, FTP, and
others.
● One of the main reasons behind this is that PHP can be easily embedded in
HTML files and HTML codes can also be written in a PHP file.
● The thing that differentiates PHP from the client-side language like HTML is,
PHP codes are first executed on the server and then the result is returned to
the browser.
● The only information that the client or browser knows is the result returned
after executing the PHP script on the server and not the actual PHP codes
● PHP files can support other client-side scripting languages like CSS and
JavaScript.
Working of PHP
PHP scripts are executed on the server. Here’s a typical flow of how PHP works:
● The server processes the PHP code. The PHP interpreter parses the script,
● The server sends the generated HTML back to the client’s browser, which
This server-side processing allows for dynamic content generation and ensures that
receives the request and processes it along with database interactions (if required)
and generates the response in the client understandable format, and then the server
In the above Client-Server model, the web browser can be used as a client and it
understands simple stuff like HTML, JavaScript and CSS, Apache can be used as a
server and it translates PHP script into a browser understandable format and MySQL
Features of PHP
Advantages of PHP
available for anyone to use and distribute. This openness has fostered a
large and active community of developers who continuously contribute to its
resources.
applications.
● Frameworks and CMS: There are popular PHP frameworks like Laravel,
● Server-Side Scripting: PHP scripts are executed on the server, reducing the
load on the client’s side. This server-side scripting capability is crucial for
improvements.
Disadvantages of PHP
and parameter orders. This can lead to confusion for developers, especially
applications.
● Performance: While PHP performs well for many web applications, it may
performance.
● Not Suitable for Large-Scale Applications: While PHP is suitable for small
to medium-sized projects, it might not be the best choice for extremely large
preferred.
supports OOP, its implementation has been criticized for not being as robust
as in some other languages. However, recent versions have introduced
These tags are also called ‘Canonical PHP tags’. Everything outside of a pair of
opening and closing tags is ignored by the PHP parser. The open and closing tags are
Comments are used to make code more readable by explaining the purpose of specific
As the name suggests, these are single line or short relevant explanations that one
can add to their code. To add this, we need to begin the line with (//) or (#).
It is used to accommodate multiple lines with a single tag and can be extended to
many lines as required by the user. To add this, we need to begin and end the line
with (/*…*/) ,
Ex: /* This
Is
Multiline comment */
1.4 Variables
1.4.1 Declaring Variables
A variable is a named memory location in which we can store values for the
● A variable can have a short name (like $x and $y) or a more descriptive name
● In PHP, The variable names are case - sensitive, so the variable name $a is
different from $A
Syntax for variable declaration:
$variablename = value;
Examples:
In PHP, it’s important to follow certain naming conventions for PHP variables to
1. Start with a Letter or Underscore: Variable names must begin with a letter
The scope of a variable is the part of the script where the variable can be
referenced/used.
● local
● global
● Static
A variable declared within a function has a LOCAL SCOPE and can only be accessed
Any declaration of a variable outside the function with the same name (as within the
<?php
$num = 60;
function local_var() {
local_var();
?>
O/P:
The variables declared outside a function are called global variables. These
Ex:
<?php
$num = 20;
global_var();
?>
o/p:
2.1 .PHP The global Keyword
The global keyword is used to access a global variable from within a function.
To do this, use the global keyword before the variables (inside the function)
Ex:
<!DOCTYPE html>
<html>
<body>
<?php
$x = 5;
$y = 10;
function myTest() {
global $x, $y;
$y = $x + $y;
}
</body>
</html>
o/p:
3. The static Keyword
when a function is completed/executed, all of its variables are deleted. But sometimes
we need to store the variables even after the completion of function execution. To do
this, we use the static keywords and the variables are then called static variables
<?php
// Static Variable
static $num = 5;
$sum = 2;
$sum++;
$num++;
o/p:
NOTE: You must have noticed that $num regularly increments even after the first
function call but $sum doesn’t. This is because $sum is not static, and its memory is
<?php
// Global variable
$globalVar = 10;
function testScope() {
// Local variable
$localVar = 20;
// Accessing global variable
global $globalVar;
echo "Global Variable: $globalVar <br>";
echo "Local Variable: $localVar <br>";
// Static variable
static $staticVar = 0;
$staticVar++;
echo "Static Variable: $staticVar <br> ";
}
echo "<br><br>";
testScope();
echo "<br><br>";
testScope();
o/p:
1.4.3 PHP $ and $$ Variables
The $var (single dollar) is a normal variable with the name var that stores any value
The $$var (double dollar) is a reference variable that stores the value of the $variable
inside it.
<?php
$x = "abc";
$$x = 200;
echo $x."<br/>";
echo $$x."<br/>";
echo $abc;
?>
o/p:
declared with a specific data type. PHP allows eight different types of data
types.
○ Integer
○ Float (Double)
○ String
○ Boolean
○ Array
○ Objects
● Special Data Types
○ NULL
○ Resources
Integer :
In PHP, Integers hold whole numbers including positive and negative numbers (... -3, -2,
-1, 0, 1, 2, 3, ...). i.e., numbers without decimal point. They can be decimal (base 10),
octal (0) or hexadecimal (0x) optionally preceded by + or - sign.
<?php
// Integer Example
$integer = 42;
echo "Integer: " . $integer . "<br>";
?>
o/p:
Float :
String :
<?php
// String Example
$string = "Hello, World!";
echo "String: " . $string . "<br>";
?>
Boolean :
Boolean data types are used in conditional testing. Hold only two values,
unsuccessful events return false. NULL type values are also treated as
false in Boolean.
<?php
// Boolean Example
$booleanTrue = true;
$booleanFalse = false;
echo "Boolean True: " . var_export($booleanTrue, true) . "<br>";
echo "Boolean False: " . var_export($booleanFalse, true) . "<br>";
?>
1.5.2 User-Defined Data Types/Compound Types:
Array :
Object :
When the individual objects are created, they inherit all the properties
and behaviors from the class, but each object will have different values
for the properties.
function greet() {
return "Hello, my name is " . $this->name . " and I am " .
$this->age . " years old.";
}
}
Null :
Resource :
Resources in PHP are not an exact data type. These are basically used to
<?php
// Resource Example
$file = fopen("sample.txt", "w");
echo "Resource: " . get_resource_type($file) . "<br>";
// Clean up resource
fclose($file);
?>
Functions
Ex: strpos(),var_dump(),array(),strtoupper(),echo(),implode()
syntax:
function function_name()
--------// code—------
<?php
// Define a function
function sayHello() {
sayHello();
?>
o/p:
2. Function Parameters or Arguments in PHP
Syntax:
executable code;
<?php
}
// Call the function with arguments
?>
o/p:
<?php
defGeek("Ram", 15);
// will be considered
defGeek("Adam");
?>
o/p:
4. Returning Values from Functions
Functions can also return values to the part of program from where it is
called.
The return keyword is used to return value back to the part of program,
from where it was called.
The returning value may be of any type including the arrays and objects.
The return statement also marks the end of the function and stops the
execution after that and returns the value.
<?php
}
// storing the returned value
?>
o/p:
PHP allows us two ways in which an argument can be passed into a function:
5. 1. Pass by Value
When passing by value, PHP creates a copy of the argument and passes it to
the function.
Any changes made to the parameter inside the function will not affect the
original variable outside the function.
<?php
function addFive($num) {
}
// Calling the function
$value = 10;
addFive($value);
?>
o/p:
Any changes made to the parameter inside the function will affect the
original variable outside the function.
function addFiveByReference(&$num) {
$value = 10;
addFiveByReference($value);
?>
o/p
Ex: strpos(),var_dump(),array(),strtoupper(),echo(),implode()
syntax:
function function_name()
--------// code—------
<?php
// Define a function
function sayHello() {
sayHello();
?>
o/p:
Syntax:
executable code;
}
Parameters or arguments are variables passed to a function so it can
perform tasks based on the input values. This makes functions dynamic and
reusable.they accept input values during runtime.
<?php
?>
o/p:
<?php
defGeek("Ram", 15);
// will be considered
defGeek("Adam");
?>
o/p:
The return keyword is used to return value back to the part of program,
from where it was called.
The returning value may be of any type including the arrays and objects.
The return statement also marks the end of the function and stops the
execution after that and returns the value.
<?php
{
$product = $num1 * $num2 * $num3;
?>
o/p:
PHP allows us two ways in which an argument can be passed into a function:
5. 1. Pass by Value
When passing by value, PHP creates a copy of the argument and passes it to
the function.
Any changes made to the parameter inside the function will not affect the
original variable outside the function.
<?php
function addFive($num) {
$value = 10;
addFive($value);
?>
o/p:
5.2. Pass by Reference
Any changes made to the parameter inside the function will affect the
original variable outside the function.
function addFiveByReference(&$num) {
$value = 10;
addFiveByReference($value);
// Outside the function, the original value has been modified
?>
o/p