PHP Execution
-
Upload
aravindhsri18 -
Category
Documents
-
view
218 -
download
0
Transcript of PHP Execution
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 1/26
PHP DEMO
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 2/26
How to run PHP files on
localhost? 1. First download the xampp from
http://www.apachefriends.org/en/xampp.html
2. Extract the file and double click the exe.This will install Mysql and Apache servers.
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 3/26
Cont..
3. Once the installation is complete, you will findXAMPP under Start / Programs / XAMPP.
4. You can use the XAMPP Control Panel to start/stopall servers. Start Mysql and Apache servers.
5. C:/Program Files/XAMPP/htdocs/
6. To run the php file, you just need to browsehttp://localhost/test.php
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 4/26
C-like language
Free format - white space is ignored.
Statements are terminated by semi-colon ;
Statements grouped by { … }
Comments begin with // or a set of comments /* */
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 5/26
Continue..
Assignment is ‘=’: $a=6
Relational operators are ,< , > == ( not a singleequal)
Control structures include if (cond) {..} else { },
while (cond) { .. } , for(startcond; increment;endcond) { }
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 6/26
Continue..
Functions are called with the name followed byarguments in a fixed order enclosed in ( ) :substr(“fred”,0,2)
Case sensitive - $fred is a different variable to$FRED
Arrays are accessed with [ ] : $x[4] is the 5thelement of the array $x – indexes start at 0
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 7/26
Demo
Example script
<? PHP ……..?>
<script language="PHP">
</script>
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 8/26
Comments
PHP allows a couple of additional ways to create
comments. <?php
phpinfo(); # This is a built-in function
?> Multiple line comments. <?php
/*A script that gets information about the
PHP version being used.
*/
<? phpinfo(); ?>
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 9/26
If Use Improper Syntax
Suppose you use the wrong syntax:
<?php
print ( “A simple initialscript);
?>
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 10/26
A Little About PHP's Syntax
Some PHP Syntax Issues:
Be careful to use quotation marks, parentheses, and
brackets in pairs.
Most PHP commands end with a semicolon (;).
Be careful of case.
PHP ignores blank spaces.
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 11/26
OOModel
Procedural language
Extensive Function Library
Not fully object-oriented Java is fully object oriented – all functions have to be
in a class
In PHP, classes are additional but quite simple to use
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 12/26
DECLARING A CLASS
class MyClass {
... // List of methods
...
... // List of properties
...
}
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 13/26
Constructor
Unified constructor name __construct().
Instead of the constructor being the name of the class,
it is now declared as __construct
class MyClass
{
function __construct() {print "Inside constructor";
}
}
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 14/26
Destructor
Object destructor support by defining a__destructor() method.
Allows defining a destructor function thatruns when an object is destroyed:
class MyClass {
function __destruct() {
print ”Destroying object”; }
}
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 15/26
Class constants
Class constants.
Class definition can now include constantvalues.
using the class:
class MyClass {
const SUCCESS = "Success";
const FAILURE = "Failure";}
print MyClass::SUCCESS;
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 16/26
Interfaces
Gives the ability for a class to fulfill more than one is-arelationships. A class can inherit only from one class, butmay implement as many interfaces as it wants:
interface Display {function display();
}
class Circle implements Display {
function display() {print "Displaying circle\n";
}
}
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 17/26
Instanceof
instanceof operator.
Language-level support for is-a relationship
checking.
if ($obj instanceof Circle) {
print '$obj is a Circle';}
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 18/26
Final methods
The final keyword allows you to markmethods so that an inheriting class cannotoverload them.
class MyClass {
final function getBaseClassName() {
return __CLASS__;
}
}
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 19/26
Final classes.
After declaring a class as final It cannot beinherited.
final class FinalClass {}
class BogusClass extends FinalClass {}
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 20/26
Array
An array in PHP is a collection of key/valuepairs. This means that it maps keys (orindexes) to values.
Array indexes can be either integers orstrings
whereas values can be of any type (includingother arrays).
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 21/26
array()
Arrays can be declared using the array()construct.
Language construct, which generally takesthe following form (elements inside squarebrackets, [], are optional):
Syntax:
array([key =>] value, [key =>] value, ..)
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 22/26
Array Example
array(1, 2, 3) is the same as the more explicitarray(0 => 1, 1 => 2, 2 => 3).
☞
array("name" => "John", "age" => 28)☞ array(1 => "ONE", "TWO", "THREE") is
equivalent to array(1 => "ONE", 2 =>
"TWO", 3 => "THREE").
☞ array() an empty array
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 23/26
nested array() statement:
array(array("name" => "John", "age" => 28),
array("name" => "Barbara", "age" => 67))
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 24/26
OPERATORS
PHP contains three types of operators:unary operators, binary operators, and
one ternary operator. Binary operators are used on two
operands: 2 + 3 14 * 3.1415 $i – 1
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 25/26
Cont…
These examples are also simple examples of expressions.
PHP can only perform binary operations on
two operands that have the same type. However, if the two operands have different
types, PHP automatically converts one of
them to the other’s type, according to thefollowing rules
(unless stated differently, such as in theconcatenation operator).
8/3/2019 PHP Execution
http://slidepdf.com/reader/full/php-execution 26/26
Queries?
Any Questions
www.php.net
Community
www.phpbuilder.com: articles on PHP, discussionforums
Newsgroups
comp.lang.php