Documente Academic
Documente Profesional
Documente Cultură
http://www.apachefriends.org/en/xampp.htm l
2. Extract the file and double click the exe.
Cont..
3. Once the installation is complete, you will find
http://localhost/test.php
C-like language
Free format - white space is ignored.
comments /* */
Continue..
Assignment is =: $a=6
Relational operators are ,< , > == ( not a single equal) Control structures include if (cond) {..} else { }, while (cond) { .. } , for(startcond; increment; endcond) { }
Continue..
Functions are called with the name followed by arguments in a fixed order enclosed in ( ) :
substr(fred,0,2)
$FRED
Arrays are accessed with [ ] : $x[4] is the 5th element of the array $x indexes start at 0
Demo
Example script <? PHP ..?> <script language="PHP">
</script>
Comments
PHP allows a couple of additional ways to create comments.
<?php phpinfo(); # This is a built-in function ?>
<?php /* A script that gets information about the PHP version being used. */ <? phpinfo(); ?>
brackets in pairs.
Most PHP commands end with a semicolon (;). Be careful of case. PHP ignores blank spaces.
OOModel
Procedural language
DECLARING A CLASS
class MyClass {
Constructor
Unied 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"; } }
Destructor
Object destructor support by dening a
__destructor() method. Allows dening a destructor function that runs when an object is destroyed: class MyClass { function __destruct() { print Destroying object; } }
Class constants
Class constants. Class denition can now include constant
values. using the class: class MyClass { const SUCCESS = "Success"; const FAILURE = "Failure"; } print MyClass::SUCCESS;
Interfaces
Gives the ability for a class to fulll more than one is-a
relationships. A class can inherit only from one class, but may implement as many interfaces as it wants:
interface Display {
function display(); } class Circle implements Display { function display() { print "Displaying circle\n"; } }
Instanceof
instanceof operator. Language-level support for is-a relationship
Final methods
The final keyword allows you to mark
methods so that an inheriting class cannot overload them. class MyClass { final function getBaseClassName() { return __CLASS__; } }
Final classes.
After declaring a class as final It cannot be
Array
An array in PHP is a collection of key/value
array()
Arrays can be declared using the array()
construct. Language construct, which generally takes the following form (elements inside square brackets, [], are optional):
Syntax:
array([key =>] value, [key =>] value, ..)
Array Example
array(1, 2, 3) is the same as the more explicit
array(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
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
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 others type, according to the following rules (unless stated differently, such as in the concatenation operator).
Queries?
Any Questions www.php.net