Professional Documents
Culture Documents
Client/Server technology
Safar M. Asaad
■ It focuses on the server-side languages, tools, and libraries that professionals use to build the
■ Students will learn not only the basic syntax and mechanics of dynamic web development, but
also the best practices that separate professional developers from amateurs.
■ Upon completing this course, students will be able to build robust web applications, and will
have the foundation for independently learning new skills in the every-changing world of web
development.
■ Advanced Web Development (with PHP, MySQL) course provides students an opportunity
to build a Great Career in web and eCommerce web application development world,
■ Program is covering PHP, MySQL and Website Design Concepts and common tasks need
for deployment and administration of a website
Course Aims
■ This Course gives the students skills in the following:
1. creating rich-featured dynamic websites and web portals.
2. Understand the major areas and challenges of dynamic web
programming.
3. Distinguish web-related technologies.
4. Use advanced tools and techniques in server side web
development
5. Use a server-side scripting language, PHP
6. Use a relational DBMS, MySQL
7. Use PHP to access a MySQL database.
8. Understanding and managing the web content (CMS)
9. Design and implement
■ dynamic web applications.
■ web applications that use asynchronous communication.
■ secure 3-tier data-driven web applications.
Prerequisites
■ Basic knowledge of computer and internet
■ Ability to build basic static front-end websites using HTML, CSS and
JavaScript. Ability to use and configure HTML tags (attributes) and
listen to DOM events.
■ This module provides the skill set required to do full stack web
development work.
Teaching Methodology
■ The syllabus will be entirely covered in class, using
– All course materials, e.g., books, articles, slides and videos are
available on the class website (Moodle) which can easily be
downloaded by students at any time.
– Therefore, the students should visit and read the content of the
class website regularly.
Course Rules and Policies
■ It is highly recommended for the students to be in the
classroom in its starting time.
■ Students can ask the lecturer to leave the classroom for
reasonable excuse.
■ Students are not allowed to use smart devices during the class,
such as; cell phone, laptop, tablets ... etc.
■ Marks may or may not be awarded for attendance, but Marks
are absolutely awarded for class participation.
■ Students are allowed to come to my office during office hours.
■ For further questions or feedback, you can always contact me
through (safar.maghdid@koyauniversity.org)
Syllabus
■ The basic principles of client/server computing;
– Distinguished characteristics of client/server systems and
application areas;
– Comparison of 2 tier versus three tier client/server solutions;
Web programming model; Interactive web.
■ Mid-Term Exam
■ Preparatory Week
■ Final Exam
Assessment
■ Mid-term Exam
– Lab Exams (15%)
– Theoretical Exam (10%)
– Activities (35%)
■ Projects
■ Seminars
■ Attendance
■ Report
■ Quiz
■ Final Exam
– Theoretical (15%)
– Practical (25%)
client/server technology
■ Systems architecture describing technologies that cooperate
together on a computer network
■ All the clients and server may not be build on similar platforms yet
they can easily facilitate the transfer of data.
Disadvantages of C/S Computing
■ If all the clients simultaneously request data from the server, it
may get overloaded.
■ If the server fails for any reason, then none of the requests of
the clients can be fulfilled.
– the application tier, which is the service layer that performs detailed processing,
– and the data tier, which consists of a database server that stores information.
Safar M. Asaad
– and may include additional information encoded in URL parameters (the field-
value pairs sent via a query string),
■ Web servers wait for client request messages, process them when they arrive,
and reply to the web browser with an HTTP response message.
– The response contains a status line indicating whether or not the request
succeeded (e.g. "HTTP/1.1 200 OK" for success).
Static sites
■ A static site is one that returns the same hard-coded content from the
server whenever a particular resource is requested).
■ The server retrieves the requested document from its file system and returns
an HTTP response containing the document and a success status (usually 200
OK).
■ Most of the code to support a dynamic website must run on the server.
– back-end.
■ front-end developer
– The Front End consists of the HTML, CSS, and any Client-Side Programs
(i.e., JavaScript).
■ back-end developer
– The Back End consists of Server-Side Programs and the Database
■ load balancing,
■ content delivery network (CDN) and
■ server infrastructure issues.
Basic Models of Server-Side Programming
■ Two traditional methods for creating a webpage server-side.
– authenticate users
■ PHP can create, open, read, write, delete, and close files on the server
■ With PHP you are not limited to output HTML. You can output
images, PDF files, and even Flash movies. You can also output any
text, such as XHTML and XML.
Why PHP?
■ Many other options: ASP.NET, ColdFusion, JSP...
■ PHP is:
– compatible with almost all servers used today (Apache, IIS, etc.)
– familiar syntax.
■ all PHP script blocks start with <?php and end with ?>, which can be
put any where in the file.
<?php
?>
A typical web server request using PHP
■ browser requests a .html file (static content): server just sends that file.
■ browser requests a .php file (dynamic content): server reads it, runs
any script code inside it, then sends result across the network
■ script produces output that becomes part of the HTML page
What Do You Need?
■ To start using PHP, you can:
o install a web server on your own PC, and then install PHP
and MySQL.
/* C-style comments
These can span multiple lines */
PHP echo and print Statements
■ print are more or less the same.
o They are both used to output data to the screen.
o They can be used with or without parentheses.
Echo “hi”; or echo(“hi”);
o They can contain HTML markup.
1. String
2. Numbers
3. Boolean
4. Array
5. Object
6. NULL
String
A string is any characters between two quotes,
For Example:
– “This is a string ”,
– ʻThis is also a stringʼ
• Example:
<?php
$fName=“Azad”;
$sName=‘Ahmed’
Echo “Hello ”. $fName.” “.$sName;
?>
Numbers
There are only two types of numbers:
Integer number
You donʼt have to worry about those types, because PHP will
convert back and forth when necessary.
Example: <?php
$Number=10;
$Number2=10.3;
Echo $Number.”<br>”.$Number2 ;
?>
Boolean
Boolean has two values:
1. True
2. False
Those are keywords in PHP which means you cannot use them
for anything other than Boolean values.
Example:
<?php
$students=TRUE;
Echo $students;
?>
Null
This is the data type that represents nothing: the valueless value.
Example:
<?php
$will_be_null;
?>
Array
It is the most complex type that we have looked at yet, and that
is because it can be made up of other variable types that we
have looked at.
Example:
<?php
$cars = array("Volvo","BMW",2.6, true, null, array(6,7));
var_dump($cars);
?>
Example: <?php
$an_array= array(”PHP","BMW",2.6, true, null,);
?>
Or
<?php
$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43”;
?>
Multidimensional arrays
• A multidimensional array is an array containing one or more arrays.
• PHP understands multidimensional arrays that are two, three, or more
levels deep. However, arrays more than three levels deep are hard to
manage for most people.
• The dimension of an array indicates the number of indices you
need to select an element.
• For a two-‐dimensional array you need two indices to select an
element
• For a three-‐dimensional array you need three indices to select an
element
1. Arithmetic operators
2. Assignment operators
3. Comparison operators
4. Increment/Decrement operators
5. Logical operators
6. String operators
7. Array operators
Arithmetic operators
Arithmetic operators are used with numeric values to perform
common arithmetical operations:
Assignment operators
assignment operators are used with numeric values to write a
value to a variable:
Comparison operators
comparison operators are used to compare two values (number
or string):
Increment/Decrement operators
• They are used to increment/decrement a variable's value:
Logical operators
• logical operators are used to combine conditional statements
String operators
• PHP has two operators that are specially designed for strings
Array operators
• The PHP array operators are used to compare arrays
PHP Conditional Statements
1. if statement -‐ executes some code only if a specified condition
is true
2. if...else statement -‐ executes some code if a condition is true
and another code if the condition is false
3. if...elseif....else statement -‐ specifies a new condition to test, if
the first condition is false
4. switch statement -‐ selects one of many blocks of code to be
executed
PHP Conditional Statements
1. if statement: 2. if...else statement:
<?php <?php
$a=5; $b=2; $a=5; $b=2;
if ($a > $b) { if ($a > $b) {
echo "a is bigger than b"; echo "a is bigger than b";
} } else {
?> echo "a is smaller than b”; }
?>
3. if...elseif....else statement:
<?php
$a=5; $b=2;
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b”; }
?>
PHP Conditional Statements
• switch statement
<?php
$destination = "Tokyo";
echo "Traveling to”. $destination.”<br />";
switch ($destination){
case "Las Vegas”: echo "Bring an extra $500”;
break;
case "Amsterdam”: echo "Bring an open mind”;
break;
case "Egypt”: echo "Bring 15 bottles
Water”; break;
case "Tokyo”: echo "Bring lots of money";
break;
case "Caribbean Islands”: echo "Bring a swimsuit";
break;
Default: echo “ Have a good journey”;
}
?>
PHP Loops
• In PHP, we have the following looping statements:
1. While: <?php
$x = 1;
while($x <= 5) {
echo "The number is:”. $x.” <br>";
$x++;
}
?>
2. do...while:
<?php
$x = 6;
do {
echo "The number is:”. $x.” <br>";
$x++;
} while ($x <= 10);
?>
for Loops
<?php
3. for: for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
Syntax
4.foreach: foreach (array_expr as $value)
{
statement
}
Example
<?php
$fruits = array ("Orange", "Apple", "Banana”, "Cherry", " Mango");
foreach ( $fruits as $value )
{
echo "$value<br />”;
}?>
Loop Through an Array
<?php
Indexed Array: $cars = array("Volvo", "BMW", "Toyota");
The count() function is used to $arrlength = count($cars);
return the length (the number of
for($x = 0; $x < $arrlength; $x++)
elements) of an array
{ echo $cars[$x]; echo "<br>";
} ?>
Associative Array:
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value; echo "<br>";
}
?>
PHP Variables Scope
■ In PHP, variables can be declared anywhere in the script.
■ PHP has three different variable scopes:
1. Global
■ A variable declared outside a function has a GLOBAL
SCOPE and can only be accessed outside a function
2. Local
■ A variable declared within a function has a LOCAL
SCOPE and can only be accessed within that function:
3. Static
■ when a function is completed/executed, all of its
variables are deleted. However, sometimes we want a
local variable NOT to be deleted. We need it for a
further job.
■ To do this, use the static keyword when you first
declare the variable
Global and Local Scope
<?php
$x = 5; // global scope
function myTest() {
// using x inside this function will generate an error
echo "<p>Variable x inside function is: $x</p>";
}
Note: myTest();
echo "<p>Variable x outside function is: $x</p>";
You can have local ?>
variables with the same
<?php
name in different function myTest() {
functions, because local $x = 5; // local scope
variables are only echo "<p>Variable x inside function is: $x</p>";
recognized by the }
function in which they myTest();
are declared. // using x outside the function will generate an error
echo "<p>Variable x outside function is: $x</p>";
?>
The global Keyword
<?php
■ The global keyword is used to access a $x = 5; $y = 10;
global variable from within a function. function myTest() {
global $x, $y;
■ To do this, use the global keyword before $y = $x + $y;
the variables (inside the function) }
myTest();
echo $y; // outputs 15
?>
■ PHP also stores all global variables in an array called
$GLOBALS[index].
■ The index holds the name of the variable.
<?php
■ This array is also $x = 5; $y = 10;
accessible from within function myTest() {
functions and can be $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
used to update global }
myTest();
variables directly. echo $y; // outputs 15
?>
PHP The static Keyword
■ Then, each time the function <?php
function myTest() {
is called, that variable will
static $x = 0;
still have the information it echo $x;
contained from the last time $x++;
}
the function was called.
Safar M. Asaad
■ PHP Constants
■ PHP Sessions
PHP Functions
1. The built-in PHP functions
2. PHP User Defined Functions
Besides the built-in PHP functions, we can create our own
functions.
A function is a block of statements that can be used repeatedly
in a program whenever needed.
A function will not execute immediately when a page loads.
A function will be executed by a call to the function.
Syntax: Function names are
NOT case-sensitive
function functionName(arguments) {
code to be executed;
}
PHP Functions-Examples
Example 1 : -
<?php
A function with two function familyName($fname, $year) {
echo "$fname Refsnes. Born in $year <br>";
arguments ($fname and }
familyName("Hege", "1975");
$year). familyName("Stale", "1978");
familyName("Kai Jim", "1983");
?>
<?php
Example 2:- function setHeight($minheight = 50)
{ echo "The height is : $minheight <br>";
}
A function with a Default setHeight(350);
setHeight(); // will use the default value of 50
Argument Value setHeight(135);
setHeight(80);
?>
PHP Functions-Examples
■ Example 1 : -
<?php
function mySum($numX, $numY){
$total = $numX +
$numY; return $total;
}
$myNumber = 0;
echo "Before the function, myNumber = ". $myNumber ."<br />";
$myNumber = mySum(3, 4); // Store the result of mySum in
$myNumber
echo "After the function, myNumber = " . $myNumber ."<br />";
?>
print_r($temp);
Out Put: -
Array(
[0] => This
[1] => is
[2] => a
[3] => sentence
[4] => with
[5] => seven
[6] => words
)
PHP Constants
■ A constant is an identifier (name) for a simple value.
■ Syntax
■ Note: Unlike variables, constants are automatically global across the entire
script.
PHP Constants
<!DOCTYPE html>
<html>
<body>
<?php
// case-sensitive constant name
define("GREETING", "Welcome to W3Schools.com!");
echo GREETING;
?>
</body>
</html>
Uniform Resource Locator
URL is used to address a document (or other data) on the web with
following these syntax rules:
scheme://prefix.domain:port/path/filename
port - defines the port number at the host (default for http is 80)
path - defines a path at the server (If omitted: the root directory of the site)
Before the browser sends the information, it encodes it using a scheme called URL encoding.
OR - URL encoding converts non-ASCII characters into a format that can be transmitted over
the Internet.
In this scheme, name/value pairs are joined with equal signs and different pairs are
separated by the ampersand (&).
name1=value1&name2=value2&name3=value3
– The page and the encoded information are separated by the ? character.
■ http://www.test.com/index.htm?name1=value1&name2=value2
■ Information sent with the GET method is visible to everyone (all variable
names and values are displayed in the URL).
■ It can be used to send ASCII as well as binary data, like sending files.
■ The data sent by POST method goes through HTTP header so security depends
on HTTP protocol.
– By using Secure HTTP you can make sure that your information is secure.
■ because the variables are not displayed in the URL, it is not possible to
bookmark the page.
HTML Forms & GET Method
• The PHP provides $_GET associative array to access all
the sent information using GET method.
<?php
if(isset($_GET["name"]) || isset($_GET["age"]) )
{
echo "Welcome ". $_GET['name']. "<br />";
echo "You are ". $_GET['age']. " years old.";
exit(); // exit here and the remains code will not be executed.
}
echo" <html>
<body>
<form action=”.$_SERVER['PHP_SELF’]." method='GET'>
Name: <input type='text' name='name’ /><br>
Age: <input type='text' name='age’ /><br>
<input type='submit' />
</form>
</body>
</html>";
?>
HTML Forms & POST Method
The PHP provides $_POST associative array to access all the sent
information using POST method.
<?php
if(isset( $_POST["name"]) || isset($_POST["age"] ))
{
echo "Welcome ". $_POST['name']. "<br />";
echo "You are ". $_POST['age']. " years
old."; exit();
} ?>
<html>
<body>
<form action =”.$_SERVER['PHP_SELF’]." method="POST”>
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
The $_REQUEST variable
The PHP $_REQUEST variable contains the contents of both
$_GET, $_POST.
<?php
if( isset($_REQUEST["name"]) || isset($_REQUEST["age"] ))
{
echo "Welcome ". $_REQUEST['name']. "<br />";
echo "You are ". $_REQUEST['age']. " years
old."; exit();
} ?>
<html>
<body>
<form action =”.$_SERVER['PHP_SELF’]." method="POST”> Name:
<input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
PHP Global Variables - Superglobals
■ they are variables which are always accessible, regardless of
scope - and you can access them from any function, class or file
without having to do anything special, like:
■ $_SERVER
■ $_REQUEST
■ $_POST
■ $_GET
■ $_SESSION
■ $_COOKIE
Element/Code
$_SERVER['PHP_SELF']
PHP
Description
Returns the filename of the currently executing script
$_SERVER['GATEWAY_INTERFACE']
$_SERVER['SERVER_ADDR'] $_SERVER
Returns the version of the Common Gateway Interface (CGI) the server is
using Returns the IP address of the host server
$_SERVER['SERVER_NAME'] Returns the name of the host server (such as localhost)
$_SERVER['SERVER_SOFTWARE'] Returns the server identification string (such as Apache/2.2.24)
$_SERVER['SERVER_PROTOCOL'] Returns the name and revision of the information protocol (such as
$_SERVER['REQUEST_METHOD'] HTTP/1.1) Returns the request method used to access the page (such as
$_SERVER['REQUEST_TIME'] POST)
$_SERVER['QUERY_STRING'] Returns the timestamp of the start of the request (such as 1377687496)
$_SERVER['HTTP_ACCEPT'] Returns the query string if the page is accessed via a query string
$_SERVER['HTTP_ACCEPT_CHARSET'] Returns the Accept header from the current request
$_SERVER['HTTP_HOST'] Returns the Accept_Charset header from the current request (such as utf-8,ISO-8859-1)
$_SERVER['HTTP_REFERER'] Returns the Host header from the current request
$_SERVER['HTTPS'] Returns the complete URL of the current page (not reliable because not all user-agents support it)
$_SERVER['REMOTE_ADDR'] Is the script queried through a secure HTTP protocol
$_SERVER['REMOTE_HOST'] Returns the IP address from where the user is viewing the current page
$_SERVER['REMOTE_PORT'] Returns the Host name from where the user is viewing the current page
$_SERVER['SCRIPT_FILENAME'] Returns the port being used on the user's machine to communicate with the web server
$_SERVER['SERVER_ADMIN'] Returns the absolute pathname of the currently executing script
Returns the value given to the SERVER_ADMIN directive in the web server configuration file (if your
script runs on a virtual host, it will be the value defined for that virtual host) (such as
$_SERVER['SERVER_PORT'] you@example.com)
$_SERVER['SERVER_SIGNATURE'] Returns the port on the server machine being used by the web server for communication (such as
$_SERVER['PATH_TRANSLATED'] 80) Returns the server version and virtual host name which are added to server-generated pages
$_SERVER['SCRIPT_NAME'] Returns the file system based path to the current script
$_SERVER['SCRIPT_URI'] Returns the path of the current script
Returns the URI of the current page
Forms - Required Fields
<!DOCTYPE HTML> <html> <head><style> .error {color: #FF0000;} </style>
</head> <body>
<?php
$nameErr = $genderErr = ""; // define variables and set to empty values
$name = $gender = $comment = "”;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
}
if (empty($_POST["comment"])) {
$comment = "";
} else {
$comment = test_input($_POST["comment"]);
} Continue >>
Forms - Required Fields
if (empty($_POST["gender"])) {
$genderErr = "Gender is required";
} else {
$gender = test_input($_POST["gender"]);
}
}
function test_input($data) {
$data = trim($data); //Removes whitespace or other
characters from both sides of a string
return $data;
}
?>
Continue >>
Forms - Required Fields
<h2>PHP Form Validation Example</h2>
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
Name: <input type="text" name="name">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
Gender:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
<span class="error">* <?php echo $genderErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
Continue >>
Forms - Required Fields
<?php
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo
$comment;
echo "<br>";
echo $gender;
?>
</body>
</html>
PHP File Inclusion
■ You can include the content of a PHP file into another PHP file
before the server executes it.
require 'filename';
include() VS require() Function
■ Example: -
<?php
echo "<p>Copyright © 1999-" . date("Y") . " W3Schools.com</p>";
?>
■ To include the footer file into Home.php page, use the include
statement or required statement:
html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>
</body>
</html>
PHP Sessions
■ It is a way to store information (in variables) to be used across
multiple pages.
■ By default, session variables last until the user closes the browser.
Starting a PHP session
■ You must first start the session. When you start a session,
■ This code will register the user's session with the server, allow
you to start saving user information and assign a UID (unique
identification number) for that user's session.
Storing a session variable
■ Session variables are set with the PHP global variable:
$_SESSION.
■ Now, let's create a new page called ”index.php". In this page, we start
a new PHP session and set some session variables, then link it to
test2.php
<?php <?php
session_start(); ?> session_start(); ?>
<html> <body> <html> <body>
<?php <?php
$_SESSION['color'] = 'red'; if(isset($_SESSION['color']))
// store session data echo "my favorite Color = ".
echo "my favorite Color = $_SESSION['color']; //retrieve data
". ?>
$_SESSION['color']; //retrieve data <br>
?> <a href="test_session.php"> Go
<br> back</a>
<a href="test2_session.php"> NEXT </body> </html>
Page To Check Session</a>
</body> </html>
cleaning and destroying a session
■ session's data is temporary and does not require that you explicitly clean after
yourself, you may wish to delete some data for your various tasks.
■ For Example: -
– You are running an online business and a user used your website to
buy your goods.
– The user has just completed a transaction on your website and you now
want to remove everything from their shopping cart
<?php
session_start();
if(isset($_SESSION['cart']))
unset($_SESSION['cart']);
?> <?php
session_start();
■ You can also completely destroy the session session_destroy();
?>
entirely by calling the session_destroy
function.
More Advanced topics
PHP heredoc string
■ When you place variables in a double-quoted string, PHP will expand the
variable names. If a string contains the double quotes (“), you need to escape
them using the backslash character(\).
$he = 'Bob';
$she = 'Alice';
$text = "$he said, \"PHP is awesome\". \"Of course.\" $she agreed.";
echo $text;
■ PHP heredoc strings behave like double-quoted strings, without the double-
quotes.
– It means that they don’t need to escape quotes and expand variables.
$he = 'Bob';
$she = 'Alice';
$text = <<<TEXT
$he said "PHP is awesome". "Of course" $she agreed."
TEXT;
echo $text;
PHP heredoc syntax
■ First, start with the $str = <<<IDENTIFIER
place a string here
– <<< operator,
it can span multiple lines
– an identifier, and and include single quote ' and double quotes "
IDENTIFIER;
– a new line
■ Second, specify the string, which can span multiple lines and includes single quotes (‘)
or double quotes (“).
■ Third, close the string with the same identifier.
– The identifier must contain only alphanumeric characters and underscores and
start with an underscore or a non-digit character.
– The character before and after the closing identifier must be a newline character
defined by the local operating system.
PHP heredoc strings’ use cases
■ In practice, the heredoc syntax is used to define a
echo $header;
PHP Nowdoc syntax
■ A nowdoc string is similar to a heredoc string except that it doesn’t expand
the variables.
$he = 'Bob';
$she = 'Alice';
$str = <<<'IDENTIFIER'
$he said "PHP is awesome". "Of course" $she
agreed." IDENTIFIER;
echo $str;
PHP type casting
Cast Operators Conversion
(array) Array
(bool) or (boolean) Boolean
(int) or (integer) Integer
(object) Object
(float) Float echo (int)12.5 . '<br>'; // 12
(string) String $amount = (float)100;
echo $amount."<br>"; // 100
$message = 'Hi';
$num = (int) $message;
echo $num."<br>"; // 0
$qty = null;
echo (int)$qty; // 0
PHP Anonymous Functions
■ An anonymous function is a function that doesn’t have a name.
■ Since the function doesn’t have a name, you need to end it with a
semicolon (;)
■ To use the variables from the parent scope inside an anonymous function,
you place the variables in the use construct as follows:
– When parentheses () is appended to a variable, PHP will look for the function
whose name is the same as the value of the variable and execute it.
<?php
$f = ''strlen;
echo $f('Hello'); 5
■ First, define a variable $f and initialize its value to the 'strlen' literal string.